2014-03-27 130 views
0

我想保存在SD卡中的图像。我正在关注this文档。保存图像文件在SD卡中的Firefox操作系统

$('.btnSave').on('click', function() { 

     var imageRawData = canvas.toDataURL("image/png") ; 
     var sdcard = navigator.getDeviceStorage("sdcard"); 
     var file = new Blob([imageRawData], { type: "image/png" }); 
     var request = sdcard.addNamed(file, "FilertedImage.png"); 

       request.onsuccess = function() { 
       var name = this.result; 
       console.log('File "' + name + '" successfully wrote on the sdcard storage area'); 

       } 
       request.onerror = function (e) { 
       console.log('Unable to write the file: ' + e.target.error.name); 

       } 
    }); 

在本文档中我发现,“的照片只接受斑点具有有效image mime type。那么如何使用javascript将imageRawData转换为有效的图像MIME类型。

回答

2

我已经做了类似如下 - 保存,然后股份:

function saveAndSend(blob) { 
    var sdcard = navigator.getDeviceStorage("sdcard"); 
    var request = sdcard.addNamed(blob, "test/mycanvas.png"); 

    //could just share the blob instead of saving 
    request.onsuccess = function() { 
     var sharingImage = new MozActivity({ 
      name: "share", 
      data: { 
       type: "image/*", 
       number: 1, 
       blobs: [blob], 
       filenames: ["mycanvas.png"], 
       filepaths: ["test/mycanvas.png"] 
      } 
     }); 
    } 

    // An error could occur if a file with the same name already exist 
    request.onerror = function() { 
     alert('Unable to write the file: ' + this.error.name); 
    } 

} 


var cnv = document.getElementById('myCanvas'); 
cnv.toBlob(function (blob) { 

    //var sdcard = navigator.getDeviceStorage("pictures"); 
    var sdcard = navigator.getDeviceStorage("sdcard"); 
    var request = sdcard.delete("test/mycanvas.png"); 
    //try to delete in case it exists 
    request.onsuccess = function() { 
     saveAndSend(blob); 
    } 

    request.onerror = function() { 
     saveAndSend(blob); 
    } 


}); 
+0

感谢您的回复。我已经访问过你的个人资料,看到你已经回答了很多关于Firefox的问题。好人!!!!!。所以,另一个请求...请看看http://stackoverflow.com/questions/22682254/how-can-i-share-image-in-facebook-in-firefox-of-using-javascript。我需要这个。 –

+0

我看着那个问题。你用亚当的方法犯了什么错误? –

+0

其实我想知道应用程序域,打包应用程序平台的价值。 –