【问题标题】:Minio with the iOS AWS S3 SDK SignatureDoesNotMatchMinio 与 iOS AWS S3 开发工具包 SignatureDoesNotMatch
【发布时间】:2017-09-06 04:03:23
【问题描述】:

我有一个 iOS 应用程序可以上传/下载到亚马逊的 S3。我想用我自己的 Minio 云替换 Amazon 的 S3。

我按照此处https://github.com/minio/minio 的快速教程进行了操作,并且我在本地主机上运行了 Minio,我可以使用 s3cmd (https://docs.minio.io/docs/s3cmd-with-minio) 放置文件。

很遗憾,我无法让它在我的 iOS 应用中运行。

我正在使用 AWS SDK v2.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" 级别=错误 msg =“{\”方法\“:\”put \“,\”path \“:\ \ mybucket / 28ab7d6dcfc441029555ebc0.aaff6e4e2-2017040716120228839-0700 / foo_28ab7d6dcfc44102955ebc0.aeff6e4e2-20170707122-2017070712955ebc0.aeff6e4e2-20170707122-2017070700_v2.json_bin \”query \“:\ "\",\"header\":{\"Accept\":[\"/\"],\"Accept-Encoding\":[\"gzip, 放气\"],\"接受语言\":[\"en-us\"],\"授权\":[\"AWS4-HMAC-SHA256 凭证=LNTXV0YMMZ9SY7MD0ACZ/20170410/us-east-1/s3/aws4_request, SignedHeaders=内容长度;内容类型;主机;用户代理;x-amz-日期, 签名=7b2f4172dd926ba84c7edba5170028e0f9361bd8a656ad8f01c7e232f585ab31\"],\"Connection\":[\"keep-alive\"],\"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\":[\"20170410T233620Z\"]}}" cause="签名不匹配" source="[object-handlers.go:472:objectAPIHandlers.PutObjectHandler()]"

在 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;
}

【问题讨论】:

标签: ios amazon-web-services amazon-s3 minio


【解决方案1】:

请替换accessKeysecretKeyurl,根据需要更改区域,服务必须设置为.S3

(AWSS3url中输入xxxx:9000会自动删除端口号,目前只支持不带端口的完整url,所以请确保你有一个到端口9000的域映射,你可能需要参考这个Setup Nginx proxy with Minio Server)

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
  ...
}

Full example project here

注意,您还需要应用以下更改以使其完全正常工作https://github.com/aws/aws-sdk-ios/pull/638

【讨论】:

    猜你喜欢
    • 2011-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-01
    • 1970-01-01
    • 2019-06-26
    • 2015-04-15
    • 2011-10-23
    相关资源
    最近更新 更多