2013-04-09 42 views
0

我正在使用Winjs(javascript for windows 8应用程序)。 我想要的是通过给出路径从静态图像的特定URL创建一个简单的blob对象。 解决方案是什么? 任何帮助将不胜感激。如何从图像url创建Blob对象?

回答

0

'MSApp.CreateFileFromStorageFile()`将在下面使用。如果您需要使用WinJS.xhr()发送文件,则可以将其设置为xhrOptions中的数据。

var uri = new Windows.Foundation.Uri('ms-appx:///images/IMG_0550.jpg'); 
     var self = this; 
     Windows.Storage.StorageFile.getFileFromApplicationUriAsync(uri).then(function ongetfilecomplete(storageFile) 
     { 
      var file = MSApp.createFileFromStorageFile(storageFile); 
      var url = URL.createObjectURL(file, { oneTimeOnly: true }); 
      // assume that this.imageElement points to the image tag 
      self.imageElement.setAttribute('src', url); 
     }).then(null, function onerror(error) 
     { 

     }); 

指万一link你正在寻找上传团块到Azure上。为了将blob发送到您的web服务,代码将在这些线上。

+0

我想要从存储文件(我不想添加新功能)中得到一个图像文件:如何在我的/ images文件夹中图像实例化一个blob对象,甚至是一个空的Blob,我需要它与我的Web服务一起发送 – Brahim 2013-04-09 15:39:53

0

URL.createObjectURL(“”)应该工作。我用它所有的时间。使用其他一些网址进行测试。你可以在JS控制台的调试模式下做到这一点,使其更容易。