为head和get verbs预先签名Amazon S3 url [英] Pre-signing Amazon S3 urls for both head and get verbs

查看:77
本文介绍了为head和get verbs预先签名Amazon S3 url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Amazon S3上托管要使用预签名网址

I'm hosting files on Amazon S3 that I want to make accessible using pre-signed urls.

对于简单的GET请求,此方法非常有效。但是,有些客户端首先执行HEAD请求(以检索文件大小)。由于URL中的签名包括http动词(GET与HEAD),因此head请求失败。

For simple GET requests this works perfectly. There are some clients however that perform a HEAD request first (to retrieve the file size). Since the signature in the URL includes the http verb (GET vs HEAD), the head request fails.

客户端只需这样做:

HEAD http://(bucketname).s3.amazonaws.com/filename?AWSAccessKeyId=(mykey)&Expires=(timestamp)&Signature=(sig)
GET http://(bucketname).s3.amazonaws.com/filename?AWSAccessKeyId=(mykey)&Expires=(timestamp)&Signature=(sig)

我无法更改客户端以使用不同的head和get URL。有没有一种方法可以使亚马逊使用对同一资源接受HEAD和GET的签名?

I cannot change the clients to use a different url for head and get. Is there a way to make amazon use a signature that accepts both HEAD and GET for the same resource?

推荐答案

您还可以模拟如果为 Range 标头指定 HEAD HEAD 行为仅第一个字节。区别在于您收到的是 206 而不是 200 的代码。其次,全尺寸将出现在 Content-Range 标头中。

You can also simulate the HEAD behavior with GET if you specify Range header for first byte only. The difference will be that you receive 206 instead of 200 code. Secondly full size will be in Content-Range header.

curl -r 0- 0< URL>

这篇关于为head和get verbs预先签名Amazon S3 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆