首页 > 解决方案 > Can't set Content-Type of Azure Blob

问题描述

I am storing the data on Azure and putting Content-Type in the headers field while uploading a chunk like so:

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

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

Following is the way I am creating blobs and pushing them into a a chunk array:

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);

Following is the putChunk() function that simply sends a PUT request:

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

No matter what the content-type is set to, of blobs and chunks likewise, it always resets to application/octet-stream. What am I missing?

标签: typescriptazureazure-blob-storage

解决方案


无论 content-type 设置为什么,它总是重置为 application/octet-stream。我错过了什么?

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

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


推荐阅读