I am trying to upload an image to server which is coming from an image library. First part works by using :
<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>
Once I read the image, I put the base64 value into a hidden text field. Then, I call uploadImgAsJpg() function.
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>");
}
}
Some of this code was copied from http://ramkulkarni.com/blog/cfmobile-example-taking-picture-and-uploading-to-coldfusion-server/
When I run the code above, my cfcatch displays : ERROR File/Directory specified was not found.
Where does cfclient.file.write save a file? Is there a better way of doing this?
this solved my problem. this gets a picture from library and sends it to the server.
hope it helps someone else.
<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>