How to create a Blob object from image url?

前端 未结 2 1659
醉话见心
醉话见心 2021-01-26 11:03

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? An

相关标签:
2条回答
  • 2021-01-26 11:42

    '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.

    0 讨论(0)
  • 2021-01-26 11:52

    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.

    0 讨论(0)
提交回复
热议问题