Tag: 多部分数据

使用AFNetworking上传照片时出错

我正在上传一张照片使用AFNetworking,我得到臭名昭着的“请求身体stream枯竭”的错误。 这是我的代码:( _manager是一个AFHTTPRequestOperationManager ) NSData *imageData = UIImageJPEGRepresentation(image, 1.0); AFHTTPRequestOperation *operation = [_manager POST:address parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) { [formData appendPartWithFileData:imageData name:@"file" fileName:@"image.jpg" mimeType:@"image/jpeg"]; } success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"Success!"); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Error: %@", error); }]; [operation setUploadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) { NSLog(@"Written: %lld", totalBytesWritten); }]; 我的iPhone […]

等待多部分图像发送完成

我正在iOS7中的一个应用程序,这是一种社交networking应用程序与图像的post和后端,保存所有客户端发送的数据。 iOS客户端通过json发送post信息,发送信息后,开始使用AFNetworking通过多部分forms发送图片。 我需要在图像发送时得到通知,以便我可以刷新应用程序的主视图,包括最近发布的新post。 在实践中,如果我要求后端的最后一个post,多部分还没有完成,图像的发送被中断,并不能发送图像。 后端是在WCF开发的,并且是一个RESTful JSON Web服务。 以下是将post发送到后端的方法: +(void)addPostToServerAddtext:(NSString *)text addimage:(UIImage *)image addbeach:(NSString *)beach location:(NSString*)location; { NSLog(@"entro a addPost"); NSString *urlBackend = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"URLBackend"]; NSData* dataImage = UIImageJPEGRepresentation(image, 1.0); NSString* ImageName = [NSString stringWithFormat:@"%@_%@.jpg",idUser ,dateToServer]; NSString *jsonRequest = [NSString stringWithFormat:@"{\"Date\":\"%@\"…."]; NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@newPost",urlBackend]]; NSMutableURLRequest *request = [ [NSMutableURLRequest alloc] initWithURL:url]; NSData […]