【发布时间】:2020-05-30 00:05:48
【问题描述】:
无法使用以下代码从节点设置 azure 内容类型。它始终将内容类型存储为辛烷值流。
const { BlobServiceClient } = require('@azure/storage-blob');
const { AZURE_STORAGE_CONNECTION_STRING } = process.env;
let blobServiceClient;
async function getBlobServiceClient() {
if (!blobServiceClient) {
blobServiceClient = await BlobServiceClient.fromConnectionString(AZURE_STORAGE_CONNECTION_STRING);
}
return blobServiceClient;
}
async function uploadFile(filePath, containerName) {
const bsClient = await getBlobServiceClient();
const containerClient = bsClient.getContainerClient(containerName);
const blockBlobClient = containerClient.getBlockBlobClient('myImag6.png', { blobHTTPHeaders: { blobContentType: 'image/png' } });
try {
const res = await blockBlobClient.uploadFile(filePath);
console.log(res);
} catch (error) {
console.log(error);
}
}
以下问题似乎与此有关,但我不确定。 https://github.com/Azure/azure-sdk-for-js/issues/6192
请给我更多关于这个以及如何解决这个问题的信息。
【问题讨论】:
-
如果需要设置内容类型,请在
uplaodFile方法中添加{ blobHTTPHeaders: { blobContentType: 'image/png' } }。getBlockBlobClient无法设置。更多详情请参考docs.microsoft.com/en-us/javascript/api/@azure/storage-blob/…和docs.microsoft.com/en-us/javascript/api/@azure/storage-blob/…
标签: node.js azure content-type azure-blob-storage