[英]How to get the image from azure blob storage as file?
i have sasUrl of an image and blobName, i need to get the image as a file from the blob storage.我有图像和 blobName 的 sasUrl,我需要从 blob 存储中获取图像作为文件。
const sasurl = "https://nuocrstracc.blob.core.windows.net/templatesxxxxxxxx/ScannedTemplates/62ac240a-f44e-42d8-b09d-dc7a9e14ed91/Acord%20applications-pages-1-4_4.jpeg?st=2020-12-17T07%3A59%3A33Z&se=2020-12-17T11%3A19%3A33Z&sp=r&sv=2018-03-28&sr=b&sig=78gAtnKM%2BjjcJQFzkoIpzjWVU0GXIhvyPafuwqBjZP8%3D "
const blobName = "templates/62ac240a-f44e-42d8-b09d-dc7a9e14ed91/Test8Dec2020_21h5m"
based on these two parameters, is there any way to get the image as file like shown below?基于这两个参数,有没有办法将图像作为文件获取,如下所示?
File
lastModified: 1591167281662
lastModifiedDate: Wed Jun 03 2020 12:24:41 GMT+0530 (India Standard Time) {}
name: "ssa.jpg"
size: 954534
type: "image/jpeg"
webkitRelativePath: ""
i have tried我努力了
fetch(sasurl).then(function(response) {
return response.blob();
}).then(function(myBlob) {
console.log("myBlob",myBlob)
});
but its returns empty.但它的回报是空的。
Try with尝试
let image = 'data:image/jpeg;base64,' + myBlob;
and use this image as src in your image tag.并将此图像用作图像标签中的 src。
Or to receive as Blob what I have tried and working for pdf is to use axios and forcing responseType as blob in request.或者接收我为 pdf 尝试和工作的 Blob 是使用 axios 并在请求中强制 responseType 作为 blob。 Like this -像这样 -
axios(url, {
method: 'GET',
headers:{
'Accept': "*/*",
... <any other header needed>
},
responseType: 'blob' //Force to receive data in a Blob Format
})
.then(response => {
//Create a Blob from the Stream
const file = new Blob(
[response.data],
{type: 'application/jpeg'});
//Build a URL from the file
const fileURL = URL.createObjectURL(file);
//Open the URL on new Window
window.open(fileURL); // This should download the image directly.
})
.catch(error => {
console.log(error);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.