我有一个iOS应用程序,可以上传/下载到亚马逊的S3。我想用我自己的Minio云取代亚马逊的S3。
我在这里学习了快速教程https://github.com/minio/minio,我在本地主机上运行了Minio,我可以使用s3cmd (https://docs.minio.io/docs/s3cmd-with-minio)放置文件。
不幸的是,我无法让它在我的iOS应用程序中工作。
我使用AWSSDKv2.4.16,这样就可以更改端点,并将其设置为本地主机(http://my-imac.local:9000),并更新了访问权限和密钥,但我得到了一个SignatureDoesNotMatch错误:“我们计算的请求签名与您提供的签名不匹配。请检查您的密钥和签名方法。”
指向本地服务器:
AWSEndpoint *minioEndpoint = [[AWSEndpoint alloc] initWithURLString:@"http://my-imac.local:9000"];
AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:region
endpoint:minioEndpoint
credentialsProvider:credentialProvider];
[AWSS3 registerS3WithConfiguration:configuration forKey:s3RegionString];以下是我在本地主机上得到的信息:
time="2017-04-10T23:36:21Z“level=error msg=”{\“level=error\”level=error\“:\”level=error\“,time=\”query\“:\”\\“,\”header\“:{\”接受\“:\”/\“,\”接受--编码\“:\”gzip,平放\“,\”接受-语言\“:\”en-us\“,\“授权”:\“AWS4-HMAC-HMAC 256 Credential=LNTXV0YMMZ9SY7MD0ACZ/20170410/us-east-1/s3/aws4_request,签名头=内容长度;内容类型;主机;用户代理;Signature=7b2f4172dd926ba84c7edba5170028e0f9361bd8a656ad8f01c7e232f585ab31\",\“连接\”:\“保持-活动\”,\“内容-长度\”:\“282416\”,\"Content-Type\":\"application/octet-stream\",\“主机”:\“My-imac.local\”,\“User\”:\“aws/2.4.16 iPhone/9.1 en_US\",\“X Date\”:\“20170410T233620Z”}“cause=”签名与“cause=”不匹配
在iOS方面:
请求头是:
{
Authorization = "AWS4-HMAC-SHA256 Credential=LNTXV0YMMZ9SY7MD0ACZ/20170410/us-east-1/s3/aws4_request, SignedHeaders=content-length;content-type;host;user-agent;x-amz-date, Signature=454c8bad35bdd3a15a08c9bf555fc69f1d5c0dabad78a474eabd4d844ca69aef";
"Content-Length" = 282416;
"Content-Type" = "application/octet-stream";
Host = "my-imac.local";
"User-Agent" = "aws-sdk-iOS/2.4.16 iPhone-OS/9.1 en_US";
"X-Amz-Date" = 20170410T233622Z;
}答复:
2017-04-10 16:36:22.507 demo[7969:4711709] AWSiOSSDK v2.4.16 [Debug] AWSURLSessionManager.m line:566 | -[AWSURLSessionManager printHTTPHeadersForResponse:] | Response headers:
{
"Accept-Ranges" = bytes;
Connection = close;
"Content-Type" = "application/xml";
Date = "Mon, 10 Apr 2017 23:36:22 GMT";
Server = "Minio/RELEASE.2017-03-16T21-50-32Z (linux; amd64)";
"Transfer-Encoding" = Identity;
Vary = Origin;
"X-Amz-Request-Id" = 14B42D7AE5B09A2B;
}发布于 2017-05-14 07:28:36
请替换accessKey、secretKey和url,根据需要更改区域,服务必须设置为.S3
(如果您在AWSS3中键入xxxx:9000,它将自动删除端口号,目前它只支持不带端口的完整url,因此请确保您有到端口9000的域映射,您可能需要参考此用Minio服务器安装Nginx代理)
let accessKey = "XXXXXXX"
let secretKey = "XXXXXXX"
let credentialsProvider = AWSStaticCredentialsProvider(accessKey: accessKey, secretKey: secretKey)
let configuration = AWSServiceConfiguration(region: .USEast1, endpoint: AWSEndpoint(region: .USEast1, service: .S3, url: URL(string:"XXXXXX")),credentialsProvider: credentialsProvider)
AWSServiceManager.default().defaultServiceConfiguration = configuration
let S3BucketName = "images"
let remoteName = "test.jpg"
let fileURL = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(remoteName)
let image = UIImage(named: "test")
let data = UIImageJPEGRepresentation(image!, 0.9)
do {
try data?.write(to: fileURL)
}
catch {}
let uploadRequest = AWSS3TransferManagerUploadRequest()!
uploadRequest.body = fileURL
uploadRequest.key = remoteName
uploadRequest.bucket = S3BucketName
uploadRequest.contentType = "image/jpeg"
uploadRequest.acl = .publicRead
let transferManager = AWSS3TransferManager.default()
transferManager.upload(uploadRequest).continueWith { (task: AWSTask<AnyObject>) -> Any? in
...
}注意,您还需要应用以下更改,以使其完全工作,https://github.com/aws/aws-sdk-ios/pull/638
https://stackoverflow.com/questions/43334548
复制相似问题