You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by GitBox <gi...@apache.org> on 2020/12/14 15:50:44 UTC

[GitHub] [cordova-plugin-file] snowdream opened a new issue #448: How can i get the real js File Object from the localpath?

snowdream opened a new issue #448:
URL: https://github.com/apache/cordova-plugin-file/issues/448


   # Bug Report
   
   ## Problem
   
   ### What is expected to happen?
   I need the real js File Object, to upload it to the web server.
   
   
   ### What does actually happen?
   I get the file from `window.resolveLocalFileSystemURL`,but i find  the file is not the real js File object.
   
   When i upload it to the web server, I find the content of the file is [Object objct].
   
   
   ## Information
   
   ### Command or Code
   
   ```bash
   window.resolveLocalFileSystemURL(image.uri, (fileEntry) => {
               console.log(fileEntry)
   
               fileEntry.file((file) => {
   
   ...
   ```
   
   
   ### Environment, Platform, Device
   <!-- In what environment, on what platform or on which device are you experiencing the issue? -->
   macbook pro
   android emulator
   cordova and cordova-plugin-file
   
   
   ### Version information
   <!-- 
   What are relevant versions you are using?
   For example:
   Cordova: Cordova CLI, Cordova Platforms, Cordova Plugins 
   Other Frameworks: Ionic Framework and CLI version
   Operating System, Android Studio, Xcode etc.
   -->
   
   


----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


[GitHub] [cordova-plugin-file] breautek closed issue #448: How can i get the real js File Object from the localpath?

Posted by GitBox <gi...@apache.org>.
breautek closed issue #448:
URL: https://github.com/apache/cordova-plugin-file/issues/448


   


----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


[GitHub] [cordova-plugin-file] breautek commented on issue #448: How can i get the real js File Object from the localpath?

Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org