简体   繁体   中英

Access Denied when upload image on GCS using Django Storage Package

Image uploading on GCS in my local work properly. After deploy django prject on vm instance with load balancer, setup ssl and domain name gives error of access denied.

Forbidden at /admin/products/banner/add/
403 POST https://storage.googleapis.com/upload/storage/v1/b/new_zourie_app/o?uploadType=multipart: {
  "error": {
    "code": 403,
    "message": "Access denied.",
    "errors": [
      {
        "message": "Access denied.",
        "domain": "global",
        "reason": "forbidden"
      }
    ]
  }
}
: ('Request failed with status code', 403, 'Expected one of', <HTTPStatus.OK: 200>)

I have added multiple (like allUsers, Storage admin, Storage Object Creator, Storage Object Admin) permissions to that bucket as given in google cloud platform docs. Also updated the bucket and bucket keys in the local as well on vm instance as a result it works on locally but not on production which have uploaded on gcp.

This is because by default VM instance service account have read-only access scope to storage bucket. you have to change scope to read-write with below steps.

  1. Stop VM where your django code is deployed.
  2. Open VM instance page and click on "edit" on VM
  3. Go to service account and change below and set scope for storage as read write. this will solve your issue enter image description here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM