简体   繁体   English

如何从 azure blob 存储中获取图像作为文件?

[英]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.

相关问题 如何在 React 中显示从 Azure Blob 存储下载的图像 - How to display image downloaded from Azure Blob Storage in React 从 Angular 向 Azure 存储 Blob 添加文件 - Adding File to Azure Storage Blob from Angular 使用Intel XDK将图像从PhoneGap上传到Azure Blob存储 - Upload image from PhoneGap to Azure Blob Storage using Intel XDK 从Java的Azure Blob存储下载数据后,如何在图像中嵌入base64编码的数据? - How to embed base64 encoded data in image after downloading data from Azure Blob Storage in Javascript? 如何使用浏览器方法将文件上传到 azure blob 存储时取得进展 - How to get progress while uploading file to azure blob storage using Browser method 如何使用JavaScript将图像上传到Azure Blob存储 - How to upload image to azure blob storage using javascript 从Azure存储中获取Blob时出错(HTTP请求)[VueJs] - Error while get a blob from Azure storage (HTTP request) [VueJs] 在新选项卡中显示 Azure Blob 存储容器中的 PDF 文件 - Displaying PDF file from Azure Blob Storage container in new tab 将文件从客户端上传到Azure Blob存储| MVC - Upload File/s From Client To Azure Blob Storage | MVC 如何使用javascript从stringstream内容azure blob存储下载png文件 - How to download png file from stringstream content azure blob storage using javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM