0
我很清楚地知道,你可以指望這個線程的重複,只是因爲多次這個問題被要求以不同的方式。我沒有從這個論壇上的現有問題中找到任何解決方案,因此我將創建一個新線程。iPhone SDK:多張圖片上傳到服務器的SOAP請求
在這裏,我有一個代碼,在一次上傳多張圖片。所以,請記下「多個圖片上傳」的句子。
我要上傳1倍或2或3或4的圖像與一些文本參數和我面對的是「相同的圖像上傳多次」指的是具有對服務器多次單個圖像的問題一起。
例子:
NSString *urlString = [NSString stringWithFormat:@"%@/MultipleImageUpload",soapAction];
NSMutableURLRequest *theRequest = [[NSMutableURLRequest alloc] init];
[theRequest setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
[theRequest setHTTPShouldHandleCookies:NO];
[theRequest setTimeoutInterval:60];
[theRequest setURL:[NSURL URLWithString:urlString]];
[theRequest setHTTPMethod:@"POST"];
NSMutableData *body = [NSMutableData data];
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",BOUNDARY_MULTIPART_IMAGE];
[theRequest addValue:contentType forHTTPHeaderField: @"Content-Type"];
//parameter SecurityCode
[body appendData:[[NSString stringWithFormat:@"--%@\r\n", BOUNDARY_MULTIPART_IMAGE] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"SecurityCode\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[SEC_CODE dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
//parameter LoggedInUserID
[body appendData:[[NSString stringWithFormat:@"--%@\r\n", BOUNDARY_MULTIPART_IMAGE] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"LoggedInUserID\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@「23433」 dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
//parameter Device
[body appendData:[[NSString stringWithFormat:@"--%@\r\n", BOUNDARY_MULTIPART_IMAGE] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"Device\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@「iPhone」 dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
for (int i=0; i<[arrImgs count]; i++) {
UIImage* image = [arrImgs objectAtIndex:i];
NSData *imgData = UIImageJPEGRepresentation(image, 1.0);
[body appendData:[[NSString stringWithFormat:@"--%@\r\n", BOUNDARY_MULTIPART_IMAGE] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"product_photo\"; filename=\"%d.jpg\"\r\n", i] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Type: image/jpeg\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:imgData]];
[body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
}
// close form
[body appendData:[[NSString stringWithFormat:@"--%@--\r\n", BOUNDARY_MULTIPART_IMAGE] dataUsingEncoding:NSUTF8StringEncoding]];
// setting the body of the post to the request
[theRequest setHTTPBody:body];
return theRequest;
請讓我知道如果任何人有這個問題的解決..
感謝,
Nilesh製作M.生主