NSDictionary * alidict1 = [aliDict objectForKey:@"Credentials"];
NSString * accessKeyId = [alidict1 objectForKey:@"AccessKeyId"];
NSString * expiration = [alidict1 objectForKey:@"Expiration"];
NSString * SecurityToken = [alidict1 objectForKey:@"SecurityToken"];
NSString * accessKeySecret = [alidict1 objectForKey:@"AccessKeySecret"];
OSSFederationToken * token = [OSSFederationToken new];
token.tAccessKey = accessKeyId;
token.tSecretKey = accessKeySecret;
token.tToken = SecurityToken;
token.expirationTimeInGMTFormat = expiration;
NSLog(@"get token:%@",token);
id<OSSCredentialProvider> credential = [[OSSFederationCredentialProvider alloc]initWithFederationTokenGetter:^OSSFederationToken *{
return token;
}];
NSString *endpoint = ALIYUN_END_POINT;
OSSClient * client = [[OSSClient alloc] initWithEndpoint:endpoint credentialProvider:credential];
OSSPutObjectRequest * put = [OSSPutObjectRequest new];
put.bucketName = ALIYUN_BUCKET;
put.objectKey = fileName;
NSString * docDir = [self getDocumentDirectory];
put.uploadingFileURL = [NSURL fileURLWithPath:[docDir stringByAppendingPathComponent:fileName]];
NSLog(@"put.uploadingFileURL:%@",put.uploadingFileURL);
put.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) {
// 当前上传段长度、当前已经上传总长度、一共需要上传的总长度
NSLog(@"%lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend);
};
// put.
OSSTask * putTask = [client putObject:put];
[putTask continueWithBlock:^id(OSSTask *task) {
if (!task.error) {
NSLog(@"upload object success!");
}else{
NSLog(@"upload object failed, error: %@",task.error);
}
return nil;
}];
[putTask waitUntilFinished];
出现这个问题upload object failed, error: Error Domain=com.aliyun.oss.serverError Code=-403 "(null)" UserInfo={__name=Error, HostId=healthd-user-pic-stage.oss-cn-hangzhou.aliyuncs.com, Message=Access denied by authorizer's policy., Code=AccessDenied, RequestId=56722C6DD4C05B286BEEE823},这是什么原因呢
-------------------------
在初始化的时候,调用OSSLog.enableLog();
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。