Ios 如何在iphone的服务器上上传多张图片?

Ios 如何在iphone的服务器上上传多张图片?,ios,iphone,objective-c,Ios,Iphone,Objective C,在我的应用程序中,用户应该能够在服务器上上载多个图像(一次最多8个图像)? 我可以一次上传一张图片,但不能一次上传多张图片? 请给我推荐一些全家福,对我有帮助吗? 多谢各位 以下是我的代码: -(IBAction)upload:(id)sender { NSDateFormatter *format = [[NSDateFormatter alloc] init]; [format setDateFormat:@"yyyyMMddHHmmss"]; NSDate *now = [[N

在我的应用程序中,用户应该能够在服务器上上载多个图像(一次最多8个图像)? 我可以一次上传一张图片,但不能一次上传多张图片? 请给我推荐一些全家福,对我有帮助吗? 多谢各位

以下是我的代码:

-(IBAction)upload:(id)sender
{

NSDateFormatter *format = [[NSDateFormatter alloc] init]; [format setDateFormat:@"yyyyMMddHHmmss"];

    NSDate *now = [[NSDate alloc] init];

    NSString *imageName = [NSString stringWithFormat:@"Image_%@", [format stringFromDate:now]];

    [now release];
    [format release];

    NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
    [request setURL:[NSURL URLWithString:@"http://url"]];
    [request setHTTPMethod:@"POST"];

    /*
     Set Header and content type of your request.
     */
    NSString *boundary = [NSString stringWithString:@"---------------------------Boundary Line---------------------------"];
    NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
    [request addValue:contentType forHTTPHeaderField: @"Content-Type"];

    /*
     now lets create the body of the request.
     */
    NSMutableData *body = [NSMutableData data];
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];    
    [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"%@.jpg\"\r\n", imageName] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[NSData dataWithData:UIImageJPEGRepresentation(imageView.image, 90)]];
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    //[body appendData:[[NSString stringWithFormat:@"geotag=%@&", [self _currentLocationMetadata]] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];

    // set body with request.
    [request setHTTPBody:body];
    [request addValue:[NSString stringWithFormat:@"%d", [body length]] forHTTPHeaderField:@"Content-Length"];

    // now lets make the connection to the web
    [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
    //


}

用同样的方法上传第一张图片。你必须在向服务器发送第一张数据的同时发送数据。除此之外,没有其他内容。但是如何通过单击一个按钮在服务器上一次发送8张图片。请参考此链接。我无法打开上述链接