0

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

4

2 回答 2

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)
        {

        });

如果您正在寻找将 blob 上传到 azure,请参考链接。为了将 blob 也发送到您的 web 服务,代码将在这些行上。

于 2013-04-09T14:57:57.787 回答
0

URL.createObjectURL("") 应该可以工作。我用它所有的时间。使用其他一些 URL 对其进行测试。您可以在 JS 控制台中以调试模式执行此操作,以使其更容易。

于 2013-04-12T13:14:49.110 回答