我已阅读 MS 提供的将文件/图像上传到 Blob 存储的大部分文档。现在已经两天了,我被困住了。我找不到上传具有正确内容类型的图像的适当方法。文件/图像已上传,但上传到 BLOB 存储后的内容类型更改为“application/octet-stream”。我希望它是“image/png”或“image/jpg”等图像。
使用的 SDK 库:@azure/storage-blob
参考 :
示例代码:
const bc = new BlockBlobClient(
rhcConfig.STORAGE_CONNECTION_STRING,
rhcConfig.CONTAINER_NAME,
`IMAGES/${fileName}`
);
// let result = await bc.uploadFile(_file);
// console.log(result);
const buff = Buffer.from(file, "base64");
const stream = getStream(buff);
const streamLength = buff.length;
await bc.uploadStream(stream, streamLength, 1, { httpHeaderOptions });
Run Code Online (Sandbox Code Playgroud)
http标题选项:
const httpHeaders = {
"x-ms-blob-cache-control": "1000",
"x-ms-blob-content-type": "image/png",
"x-ms-blob-content-md5": `${md5Hash}`,
"x-ms-blob-content-encoding": "compress",
"x-ms-blob-content-language": "en",
"x-ms-blob-content-disposition": "multipart/form-data",
};
const httpHeaderOptions = { …Run Code Online (Sandbox Code Playgroud)