typescript - 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?
解决方案
无论 content-type 设置为什么,它总是重置为 application/octet-stream。我错过了什么?
问题是您正在设置块的内容类型而不是 blob 的内容类型。
为了设置 blob 的内容类型,您需要在请求中包含x-ms-blob-content-type
标头并设置值,然后您将看到 blob 的正确内容类型。image/svg+xml
Put Block List
推荐阅读
- python - 连接大型 CSV 文件中单词的最有效方法:pandas 还是 Python 标准库?
- spring-boot - Kafka 重试如何与 request.timeout 一起工作?
- rest - 我可以通过 Http Patch 方法使用查询参数吗?
- javascript - 更改 ant design radio 输入焦点
- reactjs - 我在尝试实施 JWT 身份验证时收到此错误,错误:超过最大更新深度
- r - 如何在一个循环中选择最大元素在 r 中编写一个双循环?
- apache-spark-sql - 获取格式化为 yyyyMMdd 的字符串的 M/d/yyyy 或 MM/dd/yyyy 字符串
- r - R 子集/保留至少包含两个特定文本字符串的所有行
- python - 在 Jupyter Lab for New Environment 中导入 Pandas 时出现错误消息
- python - 代码在编写时有效,但在定义时无效