我正在尝试直接从客户端将文件上传到S3。这是我要上传的代码:
var s3Options={
"params":{
"key":options.folder+'/'+recordId+extn,
'AWSAccessKeyId':policy.s3Key,
'acl':'private',
'policy':policy.s3PolicyBase64,
'signature':policy.s3Signature,
'Content-Type':fileData.type,
'Content-Length': fileData.size,
'file':fileData,
"enctype":"multipart/form-data",
}
}
现在我正在尝试上传图片和文件上传而不是图片,请求中的内容类型是二进制/八位字节流,当我在应用程序中访问该文件时,它会在控制台中显示消息: 资源解释为Image但使用MIME类型binary / octet-stream传输:
以下是我上传文件的方式: HTTP.put(' https://开头&#39 + + process.env.S3_BUCKET' .s3.amazonaws.com /&#39 + + options.folder' /&# 39; + recordId + extn,s3Options,function(error,result){ console.log(" put file",error,result) }
现在我要说我的文件的网址是https://myBucket.s3.amazonaws.com/User/avatar/profile.png。这是文件的内容:
这是发送上传文件的put请求:
Remote Address:xxxxx
Request URL:https://myBucket.s3.amazonaws.com/User/avatar/profile.png
Request Method:PUT
Status Code:200 OK
Request Headersview source
Accept:*/*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:0
Host:myBucket.s3.amazonaws.com
Origin:http://localhost:3000
Referer:http://localhost:3000/avatar
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36
Response Headersview source
Access-Control-Allow-Methods:HEAD, GET, PUT, POST, DELETE
Access-Control-Allow-Origin:*
Access-Control-Expose-Headers:ETag, x-amz-meta-custom-header
Content-Length:0
Date:Wed, 25 Feb 2015 10:42:51 GMT
ETag:"xxxxxxxxx"
Server:AmazonS3
Vary:Origin, Access-Control-Request-Headers, Access-Control-Request-Method
x-amz-id-2:yyyyyyyyyyyy
x-amz-request-id:DDDDDDDDDDD
我已经验证了s3Options中设置的内容类型,它是image / png。