我正在尝试将来自图像库的图像上传到服务器。第一部分通过使用:
<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 在哪里保存文件?有没有更好的方法来做到这一点?