[英]Firebase storage API - upload file with metada
I am using the rest api to upload files to firebase storage as described in the following answer https://stackoverflow.com/a/65462416/8634683 .
而且我想设置缓存控制元数据,但无法弄清楚。
I found the next firebase doc - https://firebase.google.com/docs/storage/web/file-metadata but didn't saw any information about the rest API.
=== 更新 ====
于是我做了一点逆向工程,发现我在使用JS-SDK的时候,库给文件加了一个前缀,有谁知道第一个长号是什么意思吗?
所以我找到了答案:
发送带有前缀和后缀的 blob 文件,如下所示:
let prefix = `
--23483860318350978727016216849495
Content-Type: application/json; charset=utf-8
Content-Disposition: form-data; name="metadata"
{"name":"${filePath}", "cacheControl":"max-age=7200","contentType":"${fileType}"}
--23483860318350978727016216849495
Content-Type: ${fileType}`
let suffix = '\n--23483860318350978727016216849495--'
let blobWithMetadata = new Blob([prefix, blob, suffix])
并添加以下标题:
headers = {
'x-goog-upload-protocol': 'multipart',
'content-type': 'multipart/related; boundary=23483860318350978727016216849495'
}
另一种选择是进行额外的调用,但使用patch
方法而不是post
并在正文中将元数据作为 json 提交。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.