通过curl路由上传到Amazon S3 [英] Uploading to Amazon S3 via curl route
问题描述
我正在尝试通过Spring Boot设置文件上传REST API.
I am trying to set up a file upload REST API via Spring Boot.
我目前有一个list/GET方法curl http://localhost:8080/api/aws/s3/list
,该方法返回存储桶中当前存在的对象的列表.
I currently have a list/GET method curl http://localhost:8080/api/aws/s3/list
which returns a list of objects that currently exist in the bucket.
对于上传,我一直在尝试:
For upload, I have been trying:
curl -F "data=@test.txt" http://localhost:8080/api/aws/s3/upload -i
哪个会产生:
HTTP/1.1 100 Continue
HTTP/1.1 200 OK
Date: Sun, 25 Jun 2017 23:28:36 GMT
X-Application-Context: application
Content-Type: application/json;charset=utf-8
Transfer-Encoding: chunked
但是,当我查看存储分区时,尚未使用新文件对其进行更新.
But when I look at the bucket, it hasn't been updated with the new file.
这是AWS上的权限问题吗?只有我的帐户具有读写访问权限.我创建的用户和组具有管理员权限.我没有添加存储桶策略.这是我的CORS配置:
Would this be a permissions issue on AWS? Only my account has read and write access. The user and group I created have admin privileges. I didn't add a Bucket Policy. This is my CORS configuration:
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>DELETE</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>Authorization</AllowedHeader>
</CORSRule>
</CORSConfiguration>
这是我的S3控制器在春季的上传部分:
Here is the upload section of my S3 Controller in spring:
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public List<PutObjectResult> upload(@RequestParam("file") MultipartFile[] multipartFiles) {
return s3Wrapper.upload(multipartFiles);
}
推荐答案
您应为S3指定使用的存储桶名称和一些参数.我猜是PUT,而不是POST.互联网上有几个命令行示例.
You should specify your using bucket name and some parameters for S3. And I guess it's PUT, not POST. There are several command line samples in the internet.
file=/path/to/file/to/upload.tar.gz
bucket=your-bucket
resource="/${bucket}/${file}"
contentType="application/x-compressed-tar"
dateValue=`date -R`
stringToSign="PUT\n\n${contentType}\n${dateValue}\n${resource}"
s3Key=xxxxxxxxxxxxxxxxxxxx
s3Secret=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
signature=`echo -en ${stringToSign} | openssl sha1 -hmac ${s3Secret} -binary | base64`
curl -X PUT -T "${file}" \
-H "Host: ${bucket}.s3.amazonaws.com" \
-H "Date: ${dateValue}" \
-H "Content-Type: ${contentType}" \
-H "Authorization: AWS ${s3Key}:${signature}" \
https://${bucket}.s3.amazonaws.com/${file}
- 在18行Shell中上传到S3(用于上传http://soltrader.net的内部版本)
- 在Bash中上传到S3
- Uploading to S3 in 18 lines of Shell (used to upload builds for http://soltrader.net)
- Uploading to S3 in Bash
这篇关于通过curl路由上传到Amazon S3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!