第一次用oss上传不上图片,求救,急!!!!
回 1楼克劳德小弟的帖子
解决了谢谢啊
-------------------------
回 1楼克劳德小弟的帖子
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 credential = [[OSSFederationCredentialProvider alloc]initWithFederationTokenGetter:^OSSFederationToken *{
return token;
}];
NSLog(@'%@,%@',accessKeyId,accessKeySecret);
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);
};
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;
}];
出现了一个新的问题,这样写完以后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=56721F398CDE4E0167DD6818}报这个错误,这是什么原因呢
赞0
踩0