如何从cfclient.camera.getPictureFromAlbum发送图像

时间:2015-02-10 23:39:22

标签: file coldfusion cfclient

-->

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

 <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在哪里保存文件?有没有更好的方法呢?

1 个答案:

答案 0 :(得分: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>
相关问题
最新问题