Take a picture, Move the file to MY App’s Photo folder…Always worked, no longer on new Android 13.
The photo plugin returns "fileURI " = file:///data/user/0/com.nsbasic.Vantastic/cache/1697768037972.jpg
(inside the cache folder of the apps sandbox). Simply passing the above file URI to the getfile() method returns a not found error. How can i convert the above “fileURI” to something that the getfile() can find? I have tried:
Dim gfileSystem -- Successfully retrieved from :
Function onDeviceReady()
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFileSys, fail0)
End Function
Function gotFileSys(fs)
gfileSystem = fs 'The fileSystem object
End Function
----------------------------------------------
Dim FileEntry 'The file object
Dim PhotoName 'The generated name by the android camera function
Dim varPicture 'New Name of photo
Dim varfileURI
Function onISPictureReturned(fileURI)
varLastSlash = InStrR(fileURI, "/", 0)
varfileURI = fileURI
console.log(fileURI)
'varROOT = InStr(1,fileURI, "Android",0)
'PhotoName = Mid(fileURI, varROOT) 'The PhoneGap root file name
PhotoName = Mid(fileURI, varLastSlash + 1)
console.log("PhotoName Only:" + PhotoName)
'Try this?
varDate = FormatDateTime(Now, vbYYYYhyphenMMhyphenDD)
varPicture = Trim(gSelectedBroker) & "-" & Trim(gSelectedChainNumber) & "-" & Trim(gSelectedStoreNumber) & "-" & gUPC & "-" & varDate
varPicture = varPicture & ".jpg"
Call MovePicIS()
End Function
Function MovePicIS()
' varEntry = window.FilePath.resolveNativePath(varfileURI)
' varEntry = window.resolveLocalFileSystemURL(varfileURI)
' varDirectory = varEntry
fsTemp = window.requestFileSystem(window.TEMPORARY,5 * 1024 * 1024)
console.log("Full Path Parameter to get file: " + varDirectory + PhotoName)
gfileSystem.root.getFile(varfileURI, { create: False }, gotFileEntryIS, fail2IS)
End Function
Function gotFileEntryIS(fe)
FileEntry = fe
' FileEntry.moveTo(gdataDir, varPicture, SubSuccess2IS, fail3IS)
varDirectory = window.resolveLocalFileSystemURL(cordova.file.dataDirectory)
varDirectory = varDirectory + "Photos"
FileEntry.moveTo(varDirectory, varPicture, SubSuccess2IS, fail3IS)
'Three lines above are a try
End Function
Function SubSuccess2IS(entry)
'NSB.MsgBox("Use [Send Data] to Process All Photos to HQ",0,"Photo Succesfully Stored")
End Function
Function onISPictureError(message)
MsgBox "Failed because " & message
End Function
Function fail2IS(error)
MsgBox "Error getting: " + error.code + " --" + PhotoName
End Function
Function fail3IS(error)
MsgBox "Error writing: " + error.code + " -- " + varPicture
End Function
That appears to error out syntax. :Uncaught SyntaxError: missing ) after argument list
I tried enclosing in javascipt/End Java script. Below is what your Translator returns in java code:
window.resolveLocalFileSystemURL(varfileURI, Function(entry) {
console.log("Here's the path: " + entry)
}
console.log("Full Path Parameter to get file: " + varDirectory + PhotoName); gfileSystem.root.getFile(entry, {
create: false
}, gotFileEntryIS, fail2IS);
}
James. Thanks for your reply. It’s funny because I used that method to create the directories PDFs and Photos under the files directory in the sandbox. Nevertheless, I used your method:
navigator.camera.getPicture(onISPictureReturned, onISPictureError)
End Function
Function onISPictureReturned(fileURI)
varLastSlash = InStrR(fileURI, "/", 0)
varfileURI = fileURI
'--------------*(see 1. Below)*
console.log(fileURI)
PhotoName = Mid(fileURI, varLastSlash + 1)
'-------------*(see 2. Below)*
console.log("PhotoName Only:" + PhotoName)
varDate = FormatDateTime(Now, vbYYYYhyphenMMhyphenDD)
varPicture = Trim(gSelectedBroker) & "-" & Trim(gSelectedChainNumber) & "-" & Trim(gSelectedStoreNumber) & "-" & gUPC & "-" & varDate
varPicture = varPicture & ".jpg"
Call GetEntry()
End Function
Function GetEntry()
window.resolveLocalFileSystemURL(varfileURI, MovePicIS(entry) )
End Function
MovePicIS(entry)
'-------------*(see 3. Below)*
console.log("Path Parameter to get file: " + entry)
gfileSystem.root.getFile(entry, { create: False }, gotFileEntryIS, fail2IS)
End Function
Function gotFileEntryIS(fe)
FileEntry = fe
varDirectory = window.resolveLocalFileSystemURL(cordova.file.dataDirectory)
varDirectory = varDirectory + "Photos"
FileEntry.moveTo(varDirectory, varPicture, SubSuccess2IS, fail3IS)
'Three lines above are a try
End Function
Function SubSuccess2IS(entry)
'NSB.MsgBox("Use [Send Data] to Process All Photos to HQ",0,"Photo Succesfully Stored")
End Function
Function onISPictureError(message)
MsgBox "Failed because " & message
End Function
Function fail2IS(error)
MsgBox "Error getting: " + error.code + " --" + PhotoName
End Function
Function fail3IS(error)
MsgBox "Error writing: " + error.code + " -- " + varPicture
End Function
and I am getting an error Code # 5 ENCODING_ERR: here is the console output:
1. file:///data/user/0/com.nsbasic.Vantastic/cache/1698757766619.jpg
2. PhotoName Only:1698757766619.jpg
3. Full Path Parameter to get file: undefined1698757766619.jpg ( undefined is my attempt to get error description)
Tip: If you’re pasting code, html or config files, surround the code with triple back ticks (```), before the first line and after the last one. It will be formatted properly. (We fixed it for you this time)
i should have triple-ticked the code block…next time. IN:
Path Parameter to get file: undefined1698757766619.jpg
the undefined is not the error description…it appears to be the directory where the cache directory where the photo was originally stored : file:///data/user/0/com.nsbasic.Vantastic/cache/ … weird how it is undefined BUT the file name itself is still in that string.