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


   `$('#saveFile').bind('click', function download() {
                var data = generateCodeFile();
                var blob = new Blob([data], {
                    type: "application/json"
                });
                if (window.cordova && cordova.platformId !== "browser") {
               document.addEventListener("deviceready", function() {
                   var folderPath = cordova.file.externalCacheDirectory;
                   window.resolveLocalFileSystemURL(
                       folderPath,
                       function(dir) {
                       dir.getFile(
                           "my.cube",
                           {
                           create: true
                           },
                           function (file) {
                               file.createWriter(
                                   function (fileWriter) {
                                   fileWriter.write(new Blob(['some file 
data'], { type: 'text/plain' }));
   
                                   fileWriter.onwriteend = function () {
                                       alert(blob)
                                   };
   
                                   fileWriter.onerror = function (err) {
                                       alert("Unable to download2");
                                       console.error(err);
                                   };
                                   },
                                   function (err) {
                                   // failed
                                   alert("Unable to download3");
                                   console.error(err);
                                   }
                                   );
                               },
                               function (err) {
                               alert("Unable to download4");
                               console.error(err);
                               }
                           );
                           },
                       function(err) {
                       alert("Unable to download5");
                       console.error(err);
                       }
                   );
               });
           } else {
               saveAs(blob, "my.cube");
           }
                // var $a = document.createElement('a');
                // $a.href = window.URL.createObjectURL(blob);
                // $a.setAttribute("download", "my.cube");
                // var evObj = document.createEvent('MouseEvents');
                // $a.click();
         //    window.URL.revokeObjectURL($a.href)
        });`
   
![微信截图_20210715094004](https://user-images.githubusercontent.com/87455764/125714545-6e9e59ad-d53e-41f8-b6ff-ed78e1a515d8.png)
   


-- 
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.

To unsubscribe, e-mail: [email protected]

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