从ios上传数据库文件到AWS s3问题

嗨,我尝试上传一个文件到我的存储桶在AWS s3没有成功。从ios上传数据库文件到AWS s3问题

我只需要从某些手机上的应用程序上传文件

我使用iOS上的8

AWS SDK版本2,这是我的上传功能的DB:

UPLOAD

NSString *fileName = DB_File; 

NSString *directoryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

NSString *filePath = [directoryPath stringByAppendingPathComponent:fileName];

NSData *fileData = [NSData dataWithContentsOfFile:filePath];

AWSS3TransferManager *transferManager = [AWSS3TransferManager defaultS3TransferManager];

AWSS3TransferManagerUploadRequest *uploadRequest = [AWSS3TransferManagerUploadRequest new];

uploadRequest.body = [NSURL fileURLWithPath:filePath];

uploadRequest.key = fileName;

uploadRequest.bucket = @"xxxx";

[[transferManager upload:uploadRequest] continueWithBlock:^id(BFTask *task) {

if (task.error) {

if ([task.error.domain isEqualToString:AWSS3TransferManagerErrorDomain]) {

switch (task.error.code) {

case AWSS3TransferManagerErrorCancelled:

case AWSS3TransferManagerErrorPaused:

{

NSLog(@"Upload failed: [%@]", task.error);

}

break;

default:

NSLog(@"Upload failed: [%@]", task.error);

break;

}

} else {

NSLog(@"Upload failed: [%@]", task.error);

}

}

if (task.result) {

dispatch_async(dispatch_get_main_queue(), ^{

NSLog(@"Upload ok: [%@]", task.error);

});

}

return nil;

}];

AppDelege.m

* *

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 

{

if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]){

[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];

}

AWSCognitoCredentialsProvider *credentialsProvider = [AWSCognitoCredentialsProvider

credentialsWithRegionType:AWSRegionxxxx

identityPoolId:@"us-xxxx-1:xxxxxx-xxxx-xxxx-xxxxx-xxxxxxx"];

AWSServiceConfiguration *configuration = [AWSServiceConfiguration configurationWithRegion:AWSRegionUSEast1

credentialsProvider:credentialsProvider];

[AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration;

return YES;

}

**

感谢

回答:

试着改变你的水桶政策,这(更换bucketName):

{ 

"Version": "2008-10-17",

"Id": "policy",

"Statement": [

{

"Sid": "allow-public-read",

"Effect": "Allow",

"Principal": {

"AWS": "*"

},

"Action": "s3:GetObject",

"Resource": "arn:aws:s3:::bucketName/*"

},

{

"Sid": "allow-public-put",

"Effect": "Allow",

"Principal": {

"AWS": "*"

},

"Action": "s3:PutObject",

"Resource": "arn:aws:s3:::bucketName/*"

}

]

}

这可以让你从你的水桶添加/读取对象,你应该阅读AWS S3 Documentation为了知道你想要什么你的政策,但现在,这应该做的伎俩。

回答:

我放弃使用AWS SDK。我用AFAmazonS3Manager尝试过,效果很好。

AFAmazonS3Manager:亚马逊S3 API的AFNetworking客户端。

以上是 从ios上传数据库文件到AWS s3问题 的全部内容, 来源链接: utcz.com/qa/263885.html

回到顶部