我正在尝试使用以下逻辑将图像上传到Amazon S3:
- (void)uploadImageToS3: (UIImage *)image {
imageData = UIImageJPEGRepresentation(image, 0.7);
AWSS3GetPreSignedURLRequest *getPreSignedURLRequest = [AWSS3GetPreSignedURLRequest new];
getPreSignedURLRequest.bucket = @"dummyimages";
getPreSignedURLRequest.key = @"test.jpg";
getPreSignedURLRequest.HTTPMethod = AWSHTTPMethodPOST;
getPreSignedURLRequest.expires = [NSDate dateWithTimeIntervalSinceNow:3600];
NSString *fileContentTypeString = @"text/plain";
getPreSignedURLRequest.contentType = fileContentTypeString;
[[[AWSS3PreSignedURLBuilder defaultS3PreSignedURLBuilder] getPreSignedURL:getPreSignedURLRequest] continueWithBlock:^id(AWSTask *task) {
if (task.error) {
NSLog(@"Error: %@", task.error);
} else {
NSURL *presignedURL = task.result;
NSLog(@"upload presignedURL is \n%@", presignedURL);
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:presignedURL];
request.cachePolicy = NSURLRequestReloadIgnoringLocalCacheData;
[request setHTTPMethod:@"PUT"];
[request setValue:fileContentTypeString forHTTPHeaderField:@"Content-Type"];
NSURLSessionUploadTask *uploadTask = [[NSURLSession sharedSession] uploadTaskWithRequest:request fromData:imageData completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) {
NSLog(@"Upload errer: %@", error);
}
NSLog(@"Done");
}];
[uploadTask resume];
}
return nil;
}];
}
我收到这样的错误:
' NSInternalInconsistencyException',原因:'服务配置为nil
。在使用此方法之前,您需要配置Info.plist
或设置defaultServiceConfiguration
。
可以帮助解决这个问题 感谢
答案 0 :(得分:0)
答案 1 :(得分:0)
您需要在负责管理Amazon身份的类中configure your service configuration。
如果您使用较新版本的MobileHub,那么AWS常量 在info.plist中配置,你需要检查这个
如果您使用的是较早版本的MobileHub,则常量文件为AWSConfiguration。
负责管理身份的类是AWSIdentityManager,其中配置服务的功能是
- (AWSTask *)initializeClients:(NSDictionary *)logins
如果您不使用MobileHub,则需要在自己的身份管理器中实现类似的功能。
答案 2 :(得分:0)
为info.Plist文件添加以下代码行
<key>NSExceptionDomains</key>
<dict>
<key>amazonaws.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSThirdPartyExceptionMinimumTLSVersion</key>
<string>TLSv1.0</string>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
<key>amazonaws.com.cn</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSThirdPartyExceptionMinimumTLSVersion</key>
<string>TLSv1.0</string>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
</dict>