- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
在我的 django 项目上(几乎)成功地从浏览器设置了 s3 上传后,我遇到了最后一个我似乎无法弄清楚的障碍。在创建签名以将某些内容上传到 s3 时,似乎没有任何方法可以忽略设置内容类型。
删除内容类型会有所帮助的原因是,在 safari 和 chrome 中,一些具有流行扩展名的文件(甚至 .zip 也不起作用)会给我一个“我们计算的请求签名与您提供的签名。请检查您的 key 和签名方法”,因为浏览器无法识别我认为的 mime 类型(至少每当我打印出来并且出现错误时,它都是空白的)。
这是我遵循的指南:https://devcenter.heroku.com/articles/s3-upload-python ,除非它无法确定 mime 类型,否则效果很好。这也是我稍微修改过的代码的副本:
import base64
from hashlib import sha1
import hmac
AWS_ACCESS_KEY = 'X'
AWS_SECRET_KEY = 'XX'
S3_BUCKET = 'XX/X/X'
object_name = urllib.quote_plus(request.GET['s3_object_name'])
print "object_name: ", object_name.lower()
mime_type = request.GET['s3_object_type']
#on some files this is blank and thats the ones that give me 403 errors from s3
print "mime Type: ", mime_type
expires = int(time.time()+15)
amz_headers = "x-amz-acl:public-read"
# Generate the PUT request that JavaScript will use:
put_request = "PUT\n\n%s\n%d\n%s\n/%s/%s" % (mime_type, expires, amz_headers, S3_BUCKET, object_name)
# Generate the signature with which the request can be signed:
signature = base64.encodestring(hmac.new(AWS_SECRET_KEY, put_request, sha1).digest())
# Remove surrounding whitespace and quote special characters:
signature = urllib.quote_plus(signature.strip())
# Build the URL of the file in anticipation of its imminent upload:
url = 'https://%s.s3.amazonaws.com/media/attachments/%s' % ('S3_BUCKET', object_name)
content = json.dumps({
'signed_request': '%s?AWSAccessKeyId=%s&Expires=%d&Signature=%s' % (url, AWS_ACCESS_KEY, expires, signature),
'url': url
})
print content
# Return the signed request and the anticipated URL back to the browser in JSON format:
return HttpResponse(content, mimetype='text/plain; charset=x-user-defined')
最佳答案
基本上这个问题可以归因于以下事实:在指南提供的 s3_upload.js 中,读取 file.type 不正确,因此我修改了这部分代码
object_name = urllib.quote_plus(request.GET['s3_object_name'])
print "object_name: ", object_name.lower()
mime_type = request.GET['s3_object_type']
#on some files this is blank and thats the ones that give me 403 errors from s3
print "mime Type: ", mime_type
到
mime_type = request.GET['s3_object_type']
print "mime Type: ", mime_type
mtype,encoding = mimetypes.guess_type(object_name)
print "guessed mime type", mtype
mime_type = mtype
然后将内容更改为
content = json.dumps({
'signed_request': '%s?AWSAccessKeyId=%s&Expires=%d&Signature=%s' % (url, AWS_ACCESS_KEY, expires, signature),
'url': url,
'mime_type' : mime_type
})
将其传递回 JavaScript 脚本。从那里我只是修改了脚本以在执行 put 时使用我的 mime_type 作为内容类型 header ,而不是它一直在执行的操作(使用 file.type)
关于python - 在浏览器中将 PUT 上传到 S3 时忽略内容类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29788113/
我正在处理批处理作业,以通过 HTableInterface 将一批 Put 对象处理到 HBase 中。有两个 API 方法,HTableInterface.put(List) 和 HTableIn
我想转置curl命令(将本地文件上传到机架空间) curl -X PUT -T screenies/hello.jpg -D - \ -H "X-Auth-Token: fc81aaa6-98a1-9
我认为执行 puts #{a} 会产生与 puts a 相同的输出,但发现情况并非如此。考虑: irb(main):001:0> a = [1,2] => [1, 2] irb(main):002:0
我尝试在我的一个移动应用程序中使用这个cordova后台服务插件(我正在使用名为Appery io的基于网络的移动应用程序开发平台)。我已经能够让相当多的 cordova/phonegap 插件正常工
传奇有多个 put。 export function* changeItemsSaga(action) { const prerequisite1 = yield select(prerequ
我正在从工作正常的 jquery $.ajax 切换到使用 AngularJS $http.put 来访问 Restful API。 我可以进行 API 调用,但 PUT 数据未发送 - 因此我的 A
我的 express 里有这个 router.put('/admin/profile?:id/actions', (req, res) => { console.log(req.body.action
我正在浏览 Ruby tutorial , 并了解到代码 puts 'start' puts puts 'end' 会输出三行,但是下面的代码 puts 'start' puts [] puts 'e
我的目标是使用 TreeMap 使 Box 键对象按 Box.volume 属性排序,同时能够将键按 Box.code 区分。在 TreeMap 中不可以吗? 根据下面的测试 1,HashMap pu
我一直在尝试使用HBase客户端库将记录列表插入HBase。 它适用于Table或HTable中的单个Put(不建议使用),但不能识别List(Puts) 错误说:预期:util.List,但是Lis
我正在使用 Google-guava-cache。将其定义为: Cache myCache= CacheBuilder.newBuilder().maximumSize(100).build();
我只是想知道threadContext.put和MDC.put之间的区别。因为,我相信两者都在做相同的操作。 最佳答案 Log4j 2 continues with the idea of the M
我的 GAE 应用程序上有一些模型,并且我已覆盖 put()关于其中一些。当我调用db.put()时有了这些实体的列表,是否可以保证覆盖 put()每个实体都会被调用? 我现在看到的是实体只是被保存而
module Lab def self.foo puts 'foo from lab' end end module M def foo puts 'foo from mo
我正在查看示例 abo3.c来自 Insecure Programming我并没有在下面的例子中摸索类型转换。有人可以启发我吗? int main(int argv,char **argc) {
我正在 symfony2.4 和 angularjs 中构建应用程序。在 Angular 中我创建了资源: app.factory('Tasks', ['$resource', function($r
到处都说[看了很多帖子] PUT 是幂等的,意味着具有相同输入的多个请求将产生与第一个请求相同的结果。 但是,如果我们使用 POST 方法发出具有相同输入的相同请求,那么它又将表现为 PUT。 那么,
这里是WebApiConfig.cs中的路由配置: config.Routes.MapHttpRoute( name: "DefaultApiPut", routeTemplate:
这两种方法有什么区别: getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke( "pressed F10"),
由于匿名 block 和散列 block 看起来大致相同。我正在玩它。我做了一些严肃的观察,如下所示: {}.class #=> Hash 好的,这很酷。空 block 被视为Hash。 print{
我是一名优秀的程序员,十分优秀!