breautek commented on issue #448:
URL: 
https://github.com/apache/cordova-plugin-file/issues/448#issuecomment-747074073


   Unfortunately the `File` type is a special type that cannot be constructed 
manually, therefore Cordova cannot give you the "real" (browser native `File`) 
object. Only the browser itself can construct native `File` objects through 
certain browser APIs.
   
   A workaround is to read the file into a blob, which can be sent to the 
server in the same way as a `File` type can be. The native `File` type is a 
`Blob`, so any API that expects a `File` type will also work with a `Blob` type.
   
   see below for an example of how to read the file as a blob:
   
   ```js
   function readBinaryFile(fileEntry) {
   
       fileEntry.file(function (file) {
           var reader = new FileReader();
   
           reader.onloadend = function() {
   
               console.log("Successful file write: " + this.result);
               displayFileData(fileEntry.fullPath + ": " + this.result);
   
               var blob = new Blob([new Uint8Array(this.result)], { type: 
"image/png" });
               displayImage(blob);
           };
   
           reader.readAsArrayBuffer(file);
   
       }, onErrorReadFile);
   }
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to