【问题标题】:Can't set Content-Type of Azure Blob无法设置 Azure Blob 的 Content-Type
【发布时间】:2019-04-08 23:41:23
【问题描述】:

我将数据存储在 Azure 上,并将 Content-Type 放在 headers 字段中,同时上传如下块:

const headers: any = {
    'Content-Range': contentRange,
    'Content-Type': "image/svg+xml",
};

const responseData: any = await putChunk(url, chunks[currentChunkIndex].blob, headers);

以下是我创建 blob 并将它们推入块数组的方式:

var blob = new Blob([file.slice(start, end)], { type: 'image/svg+xml' });
const chunk = new FileChunk(blob, file.size, start, end, file.name);
chunks.push(chunk);

以下是简单发送 PUT 请求的 putChunk() 函数:

async function putChunk(url: string, data: any, headers: any): Promise<any> {
            const options: any = {
                method: 'PUT',
                headers: headers,
                body: 
            return await fetch(url, options);
        }

无论内容类型设置为什么,同样是 blob 和块,它总是重置为 application/octet-stream。我错过了什么?

【问题讨论】:

    标签: typescript azure azure-blob-storage


    【解决方案1】:

    无论内容类型设置为什么,它总是重置为 应用程序/八位字节流。我错过了什么?

    问题在于您设置的是块的内容类型,而不是 blob 的内容类型。

    为了设置 blob 的内容类型,您需要在 Put Block List 请求中包含 x-ms-blob-content-type 标头并将值设置为 image/svg+xml,然后您将看到正确的 blob 内容类型。

    【讨论】:

      猜你喜欢
      • 2015-05-05
      • 2016-02-27
      • 2020-09-17
      • 2018-03-11
      • 2023-03-28
      • 2016-10-29
      • 1970-01-01
      • 2018-09-14
      • 2019-02-06
      相关资源
      最近更新 更多