Created
March 3, 2014 20:03
-
-
Save RhinoLance/9333441 to your computer and use it in GitHub Desktop.
Save and move images taken with Cordova camera plugin.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ModFormCommon.PhotoSuccess = function (imageURI) { | |
var fsSuccess = function (fileEntry) { | |
//alert("got image file entry: " + fileEntry.fullPath); | |
var gotFileSystem = function (fileSystem) { | |
fileSystem.root.getDirectory( | |
ModPhoto.FileStore, | |
{ create: true }, | |
function (dataDir) { | |
var iAttachmentId = parseInt(new Date().valueOf(), 10) | |
// copy the file | |
fileEntry.moveTo(dataDir, ModFormCommon.Data.InspectionId + "_" + iAttachmentId + ".jpg", | |
function (oFile) { | |
ModPhoto.QueryInsert( | |
{ | |
AttachmentId: iAttachmentId, | |
InspectionId: ModFormCommon.Data.InspectionId, | |
Comment: "", | |
Data: ModPhoto.GetRelativePath( oFile.toURL() ), | |
RequiresSync: 1 | |
}, | |
function () {}, | |
function (error) { | |
console.log("There was a problem saving a reference to photo"); | |
} | |
); | |
ModFormCommon.Data.PhotoContainer.append("<div class='photoPreview' id='image_" + iAttachmentId + "'>" + | |
"<img id='img_" + iAttachmentId + "' src='" + oFile.toURL() + "' class='photoPreview' />" + | |
"<div class='delete' onclick='ModFormCommon.RemovePhoto(\"" + iAttachmentId + "\")'>Del</div></div>"); | |
}, fsFail); | |
}, dirFail); | |
}; | |
// get file system to copy or move image file to | |
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFileSystem, | |
fsFail); | |
}; | |
// resolve file system for image | |
window.resolveLocalFileSystemURI(imageURI, fsSuccess, fsFail); | |
// file system fail | |
var fsFail = function (error) { | |
alert("Photo copy failed with error code: " + error.code); | |
}; | |
var dirFail = function (error) { | |
alert("Photo copy Directory error code: " + error.code); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment