最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Set ContentType on Azure Blob on upload from Javascript using UploadBrowserDataToBlockBlob - Stack Overflow

programmeradmin4浏览0评论

For PDF files to display in the browser - instead of downloading - you need to supply them with the application/pdf content type header.

By default, Azure Blob Storage files are set to application/octet-stream. The content type can be changed on the back-end by updating it on the blob ... we want to set it at upload time.

Uploading PDF files using the @azure/storage-blob (documentation) npm package we cannot find the correct way to set this.

Tried many iterations of the following code to no avail.

...
const blobOptions = {
    metadata: { 'contentType': 'application/pdf' },
    ... other options
};

Azure.uploadBrowserDataToBlockBlob(aborter, file, blob, blobOptions)
...
  • Note - this can be used to set the correct mime type for anything ... but browsers seem to have no problem converting .jpg, .png etc ... only has issue with .pdf that I have seen.

For PDF files to display in the browser - instead of downloading - you need to supply them with the application/pdf content type header.

By default, Azure Blob Storage files are set to application/octet-stream. The content type can be changed on the back-end by updating it on the blob ... we want to set it at upload time.

Uploading PDF files using the @azure/storage-blob (documentation) npm package we cannot find the correct way to set this.

Tried many iterations of the following code to no avail.

...
const blobOptions = {
    metadata: { 'contentType': 'application/pdf' },
    ... other options
};

Azure.uploadBrowserDataToBlockBlob(aborter, file, blob, blobOptions)
...
  • Note - this can be used to set the correct mime type for anything ... but browsers seem to have no problem converting .jpg, .png etc ... only has issue with .pdf that I have seen.
Share Improve this question edited Jul 7, 2020 at 1:04 Ruskin asked Oct 11, 2019 at 9:55 RuskinRuskin 6,1814 gold badges49 silver badges65 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

My colleague found an answer:

...
const blobOptions = {
    blobHTTPHeaders: { blobContentType: 'application/pdf' },
    ... other options
};

Azure.uploadBrowserDataToBlockBlob(aborter, file, blob, blobOptions)
...

and added the x-ms-blob-content-type header to Azure storage CORS settings.

发布评论

评论列表(0)

  1. 暂无评论