上传大型(>40mb)m4a音频文件到Google Cloud Storage(GCS)
知道如何上传 m4a 文件吗?
# python backend
bucket = client.bucket(bucket_name)
blob = bucket.blob(filename)
signed_url = blob.generate_signed_url(
version="v4",
expiration=timedelta(minutes=60),
method="PUT",
)
// front end react JS
async function upload(file: File, signed_url: str) {
const formData = new FormData()
formData.append('file', file)
await axios.put(signed_url, formData, {
headers: {
'Content-Type': file.type
},
})
}
不要使用表单数据。 请阅读这个问题,这是一个稍微不同的问题:使用 DropZone.js 通过signedUrl 将 MP3 上传到 Google Cloud Storage 已损坏
// front end react JS
async function upload(file: File, signed_url: str) {
await axios.put(signed_url, file, {
headers: {
'Content-Type': file.type
},
})
}