not_fubar_yet
not_fubar_yet

Reputation: 352

GCS storage signed url v4, m4a file upload is corrupted, but mp3 is good. python

Goal

upload a large(>40mb) m4a audio files to Google Cloud Storage(GCS)

Method

  1. get the signed url from the backend
  2. from the front end, direct upload to GCS with signed url

Result

Any idea how to get m4a files to upload?

# 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
        },
  })
}

Upvotes: 0

Views: 89

Answers (1)

not_fubar_yet
not_fubar_yet

Reputation: 352

dont use formdata. read up on this which is a slightly different problem: Uploading an MP3 using DropZone.js to Google Cloud Storage via signedUrl is corrupted

// front end react JS
async function upload(file: File, signed_url: str) {
  await axios.put(signed_url, file, {
        headers: {
          'Content-Type': file.type
        },
  })
}

Upvotes: 0

Related Questions