良い日、私は画像の配列をサーバーにアップロードしようとしています。画像はNSDataにラップされていますが、サーバーは1つの画像のみを返します。これは私のコードです。
- (void)actionSave{
NSArray *imagesArray = [NSArray arrayWithObjects:[NSData dataWithData:UIImagePNGRepresentation(self.imageViewForImageOne.image)],
[NSData dataWithData:UIImagePNGRepresentation(self.imageViewForImageTwo.image)],
[NSData dataWithData:UIImagePNGRepresentation(self.imageViewForImageThree.image)],
[NSData dataWithData:UIImagePNGRepresentation(self.imageViewForImageFour.image)], nil];
NSData *images = [NSKeyedArchiver archivedDataWithRootObject:imagesArray];
NSMutableURLRequest *requestImg = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@&mid=%@", SEND_POST_TO_WALL, [self.currentFriend objectForKey:@"uid"]]] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0f];
[requestImg setHTTPMethod:@"POST"];
NSString *boundary = @"---------------------------14737809831466499882746641449";
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
[requestImg addValue:contentType forHTTPHeaderField:@"Content-Type"];
NSMutableData *postData = [NSMutableData dataWithCapacity:[images length] + 512];
[postData setData:images];
NSMutableData *body = [NSMutableData data];
//Photo
[body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Disposition: form-data; name=\"image\"; filename=\"image.png\"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Type: image/jpeg\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:postData];
[body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
//Text
[body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"text\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[self.textView.text dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[requestImg setHTTPBody:body];
NSURLConnection *connectionForImage = [NSURLConnection connectionWithRequest:requestImg delegate:self];
if (connectionForImage) {
self.infoData = [NSMutableData data];
} else {
NSLog(@"Connection failed");
}
}
これは、サーバーが返す結果です。
array(3) {
["act"]=>
string(12) "comments.add"
["module"]=>
string(7) "account"
["mid"]=>
string(4) "7728"
}
POST:
array(1) {
["text"]=>
string(5) "Gjdgy"
}
FILES:
array(1) {
["image"]=>
array(5) {
["name"]=>
string(9) "image.png"
["type"]=>
string(10) "image/jpeg"
["tmp_name"]=>
string(14) "/tmp/php9oudKt"
["error"]=>
int(0)
["size"]=>
int(463652)
}
}
私が間違っているのは何ですか?
前もって感謝します!