2

我正在尝试将来自图像库的图像上传到服务器。第一部分通过使用:

 <cffunction access="public" name="getPicAlbum" returntype="void" >
     <cfset opt = cfclient.camera.getOptions()>
     <cfset res = cfclient.camera.getPictureFromAlbum(opt,true)>
     <cfset displayMessage("picAlbum <br><hr>", false)>
     <cfset document.getElementById('imgBase64').value=#res#>
     <cfset uploadImgAsJpg()>
 </cffunction>

读取图像后,我将 base64 值放入隐藏的文本字段中。然后,我调用 uploadImgAsJpg() 函数。

 function uploadImgAsJpg()  {
    var base64Img = document.getElementById('imgBase64').value; 
    try {
        myImage = cfclient.file.readAsBase64(base64Img);
        cfclient.file.write("newImg.jpg", myImage);
        // where does this newImg.jpg go?
        var oldFileSystem = cfclient.file.getFileSystem();
        //Get file object from the path
        var fileObj = cfclient.file.get("newImg.jpg");

        displayMessage("uploadImgAsJpg image - " + fileObj.fullPath + "<br><hr>", false);

        var newFilePath = copyFileFromTempToPersistentFileSystem(fileObj.fullPath);

                        //Now upload file to the server
                        uploadFileToServer(newFilePath);

                        //Delete temporary file
                        cfclient.file.remove(fileObj.fullPath);
                        displayMessage("Deleted temporaty file " + fileObj.fullPath + "<br><hr>");
                    } catch (any e) {
                        displayMessage("ERROR " + e.message + "<br><hr>");
                        displayMessage("ERROR " + e.detail + "<br><hr>");
                        displayMessage("ERROR " + e.TagContext + "<br><hr>");
                    }

                }

其中一些代码是从http://ramkulkarni.com/blog/cfmobile-example-taking-picture-and-uploading-to-coldfusion-server/复制的

当我运行上面的代码时,我的 cfcatch 显示:找不到指定的错误文件/目录。

cfclient.file.write 在哪里保存文件?有没有更好的方法来做到这一点?

4

1 回答 1

0

这解决了我的问题。这从库中获取图片并将其发送到服务器。

希望它可以帮助别人。

<cffunction access="public" name="getPicAlbum" returntype="void" >
    <cfset opt = cfclient.camera.getOptions()>
    <cfset res = cfclient.camera.getPictureFromAlbum(opt,false)>
    <cfset imgStr  = cfclient.file.readAsBase64(res)>
    <cfset imgFile = cfclient.file.write("newImg.jpg",imgStr)>
    <cfset cfclient.file.upload("newImg.jpg","xxx.com/?vw=uploadBase64",uploadSuccess,onUploadError)>
 </cffunction>
于 2015-02-11T17:16:40.790 回答