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