尝试使用纯文本并将其发送到s3 - 收到403错误。能够做pdf,所以我知道某些事情,比如我的密钥凭证并不重要。
我理解MIME类型text / plain包含字符串,例如可能输入textarea html元素的字符串。
我的选择帖子:
OPTIONS /simplelogin%3A27/Bill?AWSAccessKeyId=MYKEYID&Content-MD5=&Content-Type=text%2Fplain&Expires=1435969411&Signature=MYSIGNATURE&x-
amz-acl=public-read HTTP/1.1
Host: documents.s3.amazonaws.com
Connection: keep-alive
Access-Control-Request-Method: PUT
Origin: http://localhost:9000
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36
Access-Control-Request-Headers: content-type
Accept: */*
Referer: http://localhost:9000/
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8
我的403请求:
PUT /simplelogin%3A27/BILL?AWSAccessKeyId=MYKEY&Content-MD5=&Content-
Type=text%2Fplain&Expires=1435969411&Signature=MYSIGNATURE&x-amz-acl=public-read HTTP/1.1
Host: documents.s3.amazonaws.com
Connection: keep-alive
Content-Length: 10
Origin: http://localhost:9000
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36
Content-Type: text/plain;charset=UTF-8
Accept: */*
Referer: http://localhost:9000/
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8
Query String Parameters
view source
view URL encoded
AWSAccessKeyId:SECRET KEY
Content-MD5:
Content-Type:text/plain
Expires:1435969411
Signature:SECRETSIG
x-amz-acl:public-read
Request Payload
adsaasdfaf
我知道没有Content-MD5,但这不会影响pdf / docx上传。
我的代码:
function getGenericSignedUrl (res, bucket, pathToFileWithFileName, filetype, access) {
if(!access) {
access = 'public-read';
}
// set up cred
aws.config.update({accessKeyId: AWS_ACCESS_KEY, secretAccessKey: AWS_SECRET_KEY});
// get s3 object
var s3 = new aws.S3();
// what we're storing and where
var options = {
Bucket: bucket,
Key: pathToFileWithFileName,
Expires: 90,
ACL: access,
ContentMD5: '',
ContentType: filetype
}
s3.getSignedUrl('putObject', options, function(err, data) {
if(err) return res.send('Error with S3');
// formatted url for preview access
var parsedUrl = url.parse(data);
parsedUrl.search = null;
var objectUrl = url.format(parsedUrl);
// return signed url for upload and clickable url
res.json({
signed_request: data,
url_: objectUrl
});
});
}