How to create a Blob object from image url?

穿精又带淫゛_ 提交于 2019-12-04 06:44:10

问题


I am using Winjs(javascript for windows 8 app). what I want is to create a simple blob object from a specific url of my static image by giving the path. What is the solution? Any help will be appreciated.


回答1:


'MSApp.CreateFileFromStorageFile()` as used below will work. if you need to send the file using WinJS.xhr() you can set as data in 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)
        {

        });

refer the link in case you are looking for upload the blob to azure. For send the blob to your webservice also, code will be on these lines.




回答2:


URL.createObjectURL("") should work. I use it all the time. Test it with some other URLs. You could do it in debug mode in the JS console to make it easier.



来源:https://stackoverflow.com/questions/15904374/how-to-create-a-blob-object-from-image-url

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!