0
我有一个ZIP文件上传到服务器时,我使用此代码:的iOS:上传ZIP文件与AFNetworking
NSMutableURLRequest *request = [httpClient multipartFormRequestWithMethod:@"POST" path:methode parameters:nil constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *databasePath = [documentsDirectory stringByAppendingPathComponent:@"data.xml"];
ZipArchive *zip1 = [[ZipArchive alloc] init];
BOOL ret = [zip1 CreateZipFile2:[documentsDirectory stringByAppendingPathComponent:@"data.zip"]];
ret = [zip1 addFileToZip:databasePath newname:@"data.xml"];
[formData appendPartWithFileData:[NSData dataWithContentsOfFile:[documentsDirectory stringByAppendingPathComponent:@"data.zip"]]
name:@"FILE"
fileName:@"data.zip"
mimeType:@"application/zip"];
}];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation start];
ZIP文件是罚款。请求很好。但服务器响应显示该文件正在损坏。服务器只接收855字节的ZIP文件,而不是931字节。
服务器管理员告诉我(没有的iOS经验),我必须要正确设置上传类型(如在HTML的情况下会):
enctype="multipart/form-data"
http://stackoverflow.com/questions/8234186/afnetworking-uploading-a-file – iPatel 2013-03-25 14:56:32