GCS存储签名url v4,m4a文件上传已损坏,但mp3完好。蟒蛇

问题描述 投票:0回答:1

目标

上传大型(>40mb)m4a音频文件到Google Cloud Storage(GCS)

方法

  1. 从后端获取签名的url
  2. 从前端,直接上传到GCS并签名url

结果

  • mp3文件上传OK,并且可以通过GCS UI播放OK。
  • m4a文件上传正常,但已损坏,无法播放。我从 GCS 下载 m4a 文件,并在我的 mac/pc 上播放,但失败了。
  • 这在各种 mp3 和 m4a 文件大小中是一致的。

知道如何上传 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
        },
  })
}
google-cloud-storage multipartform-data pre-signed-url
1个回答
0
投票

不要使用表单数据。 请阅读这个问题,这是一个稍微不同的问题:使用 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
        },
  })
}
© www.soinside.com 2019 - 2024. All rights reserved.