簡體   English   中英

Javascript-將圖像文件寫入Blob(html5文件api)

[英]Javascript - writing image file to blob (html5 file api)

我正在使用chrome擴展程序,將用戶選擇的文件復制到擴展程序的文件系統中。 我沒有收到任何錯誤,但是當我嘗試查看圖像時,它壞了。 這是代碼示例:

 this.create = function(obj, attr, calling_model){
// Get parent directory
fs.root.getDirectory(obj.type, {create: true}, function(dirEntry) {
  // Create file
  dirEntry.getFile(obj.type+'-'+obj.id+'-'+attr.name, {create: true, exclusive: true}, function(fileEntry) {
    fileEntry.createWriter(function(fileWriter) {
      fileWriter.write(attr.value);
    }, errorHandler);
    alert('just wrote a file to: '+fileEntry.toURL());
    // Update passed object
    obj[attr.name] = fileEntry.toURL();
    calling_model.update(obj);   
  }, errorHandler); 
}, errorHandler);

};  

其中attr.value =文件輸入的值。 我覺得我應該先將文件輸入的值轉換為Blob,然后再將其寫入文件系統,但是我還沒有找到任何執行此操作的示例。 有人解決過這個問題嗎?

提前致謝...

如果attr.valueFile對象,則您的代碼應該可以工作。 我在文件系統API的HTML5Rocks文章中寫了關於“復制用戶選擇的文件”的部分,該部分應該會有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM