Having problems with CORS at GCP. Am I doing it wrong?

Viewed 36

I'm trying to upload files from my NextJs app, but Google doesn't want to allow me uploading it via SignedUrl with NextJs API. (It does work with S3). Also, I tested it on postman and it allows me to upload files. Weird.

Getting SIGNEDURL:

const options = {
  version: 'v4',
  action: 'write',
  expires: Date.now() + 15 * 60 * 1000,
  contentType: 'application/octet-stream'
}

const url = await storage
  .bucket(BUCKET_NAME) // .env variable with the bucket
  .file(path)
  .getSignedUrl(options)

Using URL to download files and track UploadProgress via axios:

axios({
url, // signed url from the function above
method: 'PUT',
headers: {
  'Content-Type': 'multipart/form-data'
},
data, // new FormData with the files on it
onUploadProgress: (progressEvent) => {
  const percentCompleted = Math.round(
    (progressEvent.loaded * 100) / progressEvent.total
  )
  updateProgressCallback({ file, percentCompleted }) // to keep track of the upload progress
}})

Also, here you have the GCP bucket cors.json config:

[
  {
   "origin": ["*"], // it is for testing purposes, later i will write the domain
   "responseHeader": ["*"],
   "method": ["GET","POST","HEAD","DELETE"],
   "maxAgeSeconds": 3600
  }
]
0 Answers
Related