相关疑难解决方法(0)

Django,Heroku,boto:直接将文件上传到Google云端存储

在Heroku上部署的Django项目中,我曾经通过boto将文件上传到Google云存储.但是,最近我必须上传大文件,这会导致Heroku超时.

我正在关注Heroku关于直接文件上传到S3的文档,并按照以下方式进行自定义:

蟒蛇:

conn = boto.connect_gs(gs_access_key_id=GS_ACCESS_KEY,
                       gs_secret_access_key=GS_SECRET_KEY)
presignedUrl = conn.generate_url(expires_in=3600, method='PUT', bucket=<bucketName>, key=<fileName>, force_http=True)
Run Code Online (Sandbox Code Playgroud)

JS:

url = 'https://<bucketName>.storage.googleapis.com/<fileName>?Signature=...&Expires=1471451569&GoogleAccessId=...'; // "presignUrl"

postData = new FormData();
postData.append(...);
...

$.ajax({
  url: url,
  type: 'PUT',
  data: postData,
  processData: false,
  contentType: false,
});
Run Code Online (Sandbox Code Playgroud)

我收到以下错误消息:

XMLHttpRequest cannot load http:/...  Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8000' is therefore not allowed access.
Run Code Online (Sandbox Code Playgroud)

编辑:

输出gsutil cors get gs://<bucketName>:

[{"maxAgeSeconds": 3600, "method": …
Run Code Online (Sandbox Code Playgroud)

django boto google-cloud-storage

7
推荐指数
1
解决办法
1136
查看次数

标签 统计

boto ×1

django ×1

google-cloud-storage ×1