OSSClient *ossclient = [OSSClient sharedInstanceManage];
[ossclient setGlobalDefaultBucketHostId:@"oss-cn-hangzhou.aliyuncs.com"];
[ossclient setGlobalDefaultBucketAcl:PUBLIC_READ] ;
[ossclient setGenerateToken:^NSString *(NSString *method, NSString *md5, NSString *type, NSString *date, NSString *xoss, NSString *resource){
NSString *signature = nil;
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:[[NSString stringWithFormat:@"http://%@/xxx/xxx?access_token=%@&appId=%@&httpMethod=%@&md5=%@&type=%@&date=%@&ossHeaders=%@&resource=%@",BASE_URL,K_ACCESSTOKEN,appId,method,md5,type,date,xoss,resource] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
[request setValue:@"application/x-www-form-urlencoded;charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
[request setHTTPMethod:@"GET"];
// 发送同步请求, data就是返回的数据
NSError *error = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error];
if (data == nil) {
NSLog(@"send request failed: %@", error);
return nil;
}
NSString *response = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"response is %@",response);
signature=resource;
return signature;
}];
OSSBucket *bucket = [[OSSBucket alloc] initWithBucket:@"deaas"];
__block int success=0;
for (int i=0; i<_comment.curTweet.imgs.count; i++) {
OSSData *testData = [[OSSData alloc] initWithBucket:bucket withKey:[NSString stringWithFormat:@"%@.jpg",[Tool getUUID]]];
[testData setData:UIImageJPEGRepresentation(_comment.curTweet.imgs
, 1) withType:@"image/jpg"];
[testData uploadWithUploadCallback:^(BOOL isSuccess, NSError *error) {
if (isSuccess) {
NSLog(@"success !!!!!!");
success++;
}
else
{
NSLog(@"errorInfo_testDataUploadWithProgress:%@", [error userInfo]);
}
} withProgressCallback:^(float progress) {
// NSLog(@"current get %f", progress);
}];
}
返回错误是
{
ArgumentName = Authorization;
ArgumentValue = "/deaas/2843009C214B453FA9F99791A7FE7970.jpg";
Code = InvalidArgument;
HostId = "deaas.oss-cn-hangzhou.aliyuncs.com";
Message = "Authorization header is invalid.";
RequestId = 54FDC171957EEB7621C202FF;
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。