简体   繁体   中英

Cordova plugin file not returning file from fileEntry

here is my code:

window.resolveLocalFileSystemURL(cameraCallback, (fileEntry) => {
  this.teste1 = fileEntry
  fileEntry.file(function (file) {
    this.teste2 = file
    let reader = new FileReader()
    reader.onloadend = function (e) {
      this.teste3 = this.result
    }
    reader.readAsDataURL(file)
  })
}, (error) => {
  this.teste4 = error
})

where cameraCallback is a "file:///path/to/file" image, which exists. I want to read this image as a file, but this.teste2 is returning empty. this.teste3 also returns empty.

Here is my filyEntry:

File Entry { "isFile": true, "isDirectory": false, "name": "1558418616412.jpg", "fullPath": "/Android/data/org.cordova.quasar.app/cache/1558418616412.jpg", "filesystem": "", "nativeURL": "file:///storage/emulated/0/Android/data/org.cordova.quasar.app/cache/1558418616412.jpg" }

How can i solve this? I tried many combinations of response, changing the reader function (e), is it a async problem? Didn't get any response to this, any example.

How can i read my fileEntry as a blob/file/base64 image?

Have you tried

let self = this

window.resolveLocalFileSystemURL(cameraCallback, (fileEntry) => {

     self.teste1 = fileEntry

     fileEntry.file(function (file) {

       self.teste2 = file

       let reader = new FileReader()

       reader.onloadend = function (e) {

         self.teste3 = self.result

       }

       reader.readAsDataURL(file)

     })

    }, (error) => {

     self.teste4 = error

    })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM