您好, 我从后台获取了policy,signature,oss_access_key_id,url这四个参数,然后尝试用post上传图片到阿里云,但是始终都上传失败,求解答,谢谢。
代码片段如下:
- (void)postOSSImageKeybucketName:(NSString *)oss_access_key_id url:(NSString *)url policy:(NSString *)policy Signature:(NSString *)signature{
if (_currentImg == nil || !_currentImg) {
return;
}
//2. 图片名字
NSString *fileName = [ShareMethod ret20bitString];
fileName = [fileName stringByAppendingString:@".jpg"];
//3. 图片二进制文件
NSData *imagedata = UIImageJPEGRepresentation(_currentImg, 0.00001);
//4. 发起网络请求
MySessionManager *manager = [MySessionManager manager];
NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
[dic setValue:fileName forKey:@"key"];
[dic setValue:oss_access_key_id forKey:@"OSSAccessKeyId"];
[dic setValue:policy forKey:@"policy"];
[dic setValue:signature forKey:@"Signature"];
[dic setValue:imagedata forKey:@"file"];
// [dic setValue:fileName forKey:@"MyFilename.jpg"];
[dic setValue:@"200" forKey:@"success_action_status"];
[manager POST:url parameters:dic constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
[formData appendPartWithFileData:imagedata name:@"upload" fileName:fileName mimeType:@"image/jpeg"];
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nonnull responseObject) {
NSLog(@"%@",responseObject);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSHTTPURLResponse *response = (NSHTTPURLResponse *)task.response;
NSLog(@"++++%ld",(long)response.statusCode);
}];
}
你需要把报错的日志或者错误信息贴出来,不然大家无法帮到你
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。