AFN传文件和参数
来源:互联网 发布:java中文相似度匹配 编辑:程序博客网 时间:2024/06/07 01:11
使用AFNetWorking传文件和参数:
#pragma mark -上传问题图片
- (void)uploadQuestionImage:(UIImage*)questionImage withQuestionID:(NSString*)questionID{
AppDelegate * app = [UIApplicationsharedApplication].delegate;
NSData *imageData =UIImageJPEGRepresentation(self.questionImage,1.0);
NSMutableDictionary * parameters = [NSMutableDictionarydictionary];
[parameters setObject:questionIDforKey:@"exID"];
NSMutableURLRequest *request = [[AFHTTPClientclientWithBaseURL:[NSURLURLWithString:dUrl_serverAddress]]multipartFormRequestWithMethod:@"POST"path:@"Path/UploadTitleImage/"parameters:parametersconstructingBodyWithBlock: ^(id<AFMultipartFormData>formData) {
[formData appendPartWithFileData:imageDataname:@"image"fileName:@"quePic.jpg"mimeType:@"image/jpeg"]; //图片
}];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperationalloc]initWithRequest:request];
[operation setUploadProgressBlock:^(NSUIntegerbytesWritten, long long totalBytesWritten,longlongtotalBytesExpectedToWrite) {
float progress = totalBytesWritten / (float)totalBytesExpectedToWrite;
NSLog(@"Sent Pic %f ..",progress);
}];
[operation start];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation*operation, id responseObject) {
NSLog(@" QuestionPictureUploadDidFinish: %@ ",[operationresponseString]);
NSString * response =[operationresponseString];
NSError *error = nil;
NSData *fileIdData = [responsedataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *dicRoot = [NSJSONSerializationJSONObjectWithData:fileIdDataoptions:NSJSONReadingMutableLeaveserror:&error];
NSDictionary *dictfil = [dicRootobjectForKey:@"json"];
int state = [[dictfilvalueForKey:@"state"]intValue];
//上传成功
if (state==1)
{
NSString *msg = [NSStringstringWithFormat:@"%@", [dictfil objectForKey:@"msg"]];
[app showMsg:msg];
}
//上传失败
else
{
NSString *msg = [NSStringstringWithFormat:@"%@", [dictfil objectForKey:@"msg"]];
[app showMsg:msg];
}
} failure:^(AFHTTPRequestOperation*operation, NSError *error) {
NSLog(@"上传失败error: %@", operation.responseString);
[app showMsg:@"上传失败"];
}];
}
0 0
- AFN传文件和参数
- AFN上传文件和检测网络状态
- 25、26、27day-文件上传和下载&ASI&AFN
- AFN上传文件
- 利用AFN上传文件
- NSUrSession和AFN
- 文件上传(AFN GCD)
- AFN上传文件,包括语音
- AFN框架上传录音文件。
- AFN解析返回的html文件和ContentType是“text/plain”类型的json文件
- AFN
- AFN
- AFN
- AFN
- AFN
- AFN
- AFN
- AFN
- Unity学习笔记——逐字显示一首诗
- HDU_1394_线段树_树状数组
- 有符号数与无符号数的运算
- 跟我一起数据挖掘(23)——C4.5
- js maxLength ie和谷歌火狐区分大小写
- AFN传文件和参数
- POJ1743---Musical Theme(后缀数组+二分)
- 归并排序求逆序数(POJ 1804,POJ 2299,HDU 4911)
- Remove Duplicates from Sorted List II--LeetCode
- 机器学习实战-k近邻算法
- Coderforces Round #296(DIV.2)
- 记忆化搜索 hdu 1331
- 自定义的选择工具不会自动绑定mapcontrol的selectionChange事件
- iOS 实现发送邮件和短信