You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by GitBox <gi...@apache.org> on 2021/01/04 14:28:15 UTC

[GitHub] [cordova-plugin-file-transfer] breautek commented on issue #297: cordova build iOS fails

breautek commented on issue #297:
URL: https://github.com/apache/cordova-plugin-file-transfer/issues/297#issuecomment-754006137


   > I read your blog post wherein you refer this plugin is due to be deprecated
   (you use the word "sunsetting") because now we can do the same with pure
   javascript.
   
   This plugin was deprecated (and there hasn't been a release to "undeprecate" it yet), but it was voted to bring it back because pure JS solutions still has some flaws in regards to efficiently working with large files.
   
   > Can you tell the corresponding javascript code for the method ft.upload?
   
   You can read the file as a blob using the `cordova-plugin-file` plugin. Example from the docs:
   
   ```javascript
   function readBinaryFile(fileEntry) {
   
       fileEntry.file(function (file) {
           var reader = new FileReader();
   
           reader.onloadend = function() {
               var blob = new Blob([new Uint8Array(this.result)], { type: "application/octet-stream" });
           };
   
           reader.readAsArrayBuffer(file);
   
       }, onErrorReadFile);
   }
   ```
   
   Once you have your blob object, you can upload using `XMLHttpRequest`:
   
   ```javascript
   var xhr = new XMLHttpRequest();
   xhr.open('POST', 'example.com/upload');
   xhr.setRequestRequestHeader('Content-Type', theFileMimeType);
   xhr.onload = function() {
      // finished uploading (or error)... check xhr.status to be sure.
   };
   xhr.send(blob);
   ```
   
   `xhr.send` accepts strings as well, so if you're files are textual (like JSON, csvs, etc...), you can also read the files as a string and upload. But the example above should work with any data type, including binary data like images.


----------------------------------------------------------------
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: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org