I'm trying to create an object URL for a freshly captured photo loaded from disk with cordova-plugin-file
, but it seems like it's not a normal window.File
instance:
const CAMERA_OPTIONS = {
quality: 50,
destinationType: Camera.DestinationType.FILE_URI,
encodingType: Camera.EncodingType.JPEG,
}
captureImage = function () {
return new Promise((resolve, reject) => {
navigator.camera.getPicture(
imageURI => resolveLocalFileSystemURL(imageURI, fileEntry => {
fileEntry.file(f => {
console.log(f instanceof Blob, f instanceof File) // false true
resolve(URL.createObjectURL(f)) // Failed to execute 'createObjectURL' on 'URL': No function was found that matched the signature provided.
}, reject),
reject,
CAMERA_OPTIONS
)
})
}
According to MDN, I should be able to pass f
to createObjectURL()
as-is:
A File object is a specific kind of Blob, and can be used in any context that a Blob can. In particular, FileReader, URL.createObjectURL(), createImageBitmap(), and XMLHttpRequest.send() accept both Blobs and Files.
The File interface doesn't define any methods, but inherits methods from the Blob interface
But that's not the case.
Also note the console log - f
is an instance of File
, but not Blob
. Strange.
I also tried to get the URL directly with fileEntry.toURL()
, but URL produced in that case is pointing to my devserver address (like http://192.168.X.X:8080/__cdvfile_cache__/photo-name.jpg
). Obviously, it's not valid and doesn't work.
Also tried stuff like URL.createObjectURL(new Blob([f], { type: 'image/jpeg' }))
but never got a valid image I could just put into img
's src
.
Am I missing something?