flaskgoogle-cloud-platformgoogle-cloud-storageflask-restfulcustom-headers

how to add custom header upload to Google Cloud Storage?


I use Flask to create an API, but I am having trouble uploading when I create custom headers to upload to my Google Cloud Storage. Fyi, the permissions details on my server are the same as my local machine to test upload of images to GCS, admin storage and admin object storage, there are no problems on my local machine. but when I curl or test upload on my server to my Google Cloud Storage bucket, the response is always the same:

"rc": 500, "rm": "403 POST https://storage.googleapis.com/upload/storage/v1/b/konxxxxxx/o?uploadType=multipart: ('Request failed with status code', 403, 'Expected one of', )"

im testing in postman using custom header : upload_key=asjaisjdaozmzlaljaxxxxx

and i curl like this : url --location --request POST 'http://14.210.211.xxx:9001/koxxx/upload_img?img_type=img_x' --header 'upload_key: asjaisjdaozmzlaljaxxxxx' --form 'img_file=@/home/user/image.png'

and I have confirmed with "gcloud auth list" that the login data that I use on the server is correct and the same with my local machine.


Solution

  • you have a permission error, to fix it use service accounts method, it's easy and straightforward.

    export KEY=$(gcloud iam service-accounts keys create $SERVICE_ACCOUNT_DEST --iam-account $SA_EMAIL)