2

我正在制作一个可以选择多张照片的应用程序,然后将这些照片保存在一个数组中,就像我可以将该照片数组发送到服务器一样......

我试过了,但我无法得到..我希望你能帮我解决这个..

这是我的代码:

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{

    NSString *mediaType=info[UIImagePickerControllerMediaType];
    NSData*dataImage=UIImageJPEGRepresentation([infoobjectForKey:@"UIImagePickerControllerOriginalImage"];
   UIImage *image = [[UIImage alloc] initWithData:dataImage];

[arrayImagenes addObject:dataImage];

    [self dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)ActualizarReporte:(id)sender {

    NSString *urlString = @"http://appsiste.com/test/uploadimage.php";

    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
    [request setURL:[NSURL URLWithString:urlString]];
    [request setHTTPMethod:@"POST"];

    NSString *boundary = @"---------------------------14737809831466499882746641449";
    NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
    [request addValue:contentType forHTTPHeaderField: @"Content-Type"];

    NSMutableData *body = [NSMutableData data];

     for (int i=0; i<[arrayImagenes count]; i++)
    {
        [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
        [body appendData:[[NSString stringWithString:[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"userfile\"; filename=\".jpg\"\r\n"]] dataUsingEncoding:NSUTF8StringEncoding]];
        [body appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
        [body appendData:[NSData dataWithData:[arrayImagenes objectAtIndex:i]]];
        [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    }
    [request setHTTPBody:body];

    NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
    NSString *returnString=[[NSString alloc]initWithData:returnData encoding:NSUTF8StringEncoding];
    NSLog(@"%@",returnString);

}

no se si estare bien lo que estoy haciendo..alguna idea por favor de como lo pueda hacer..me esta dando muchos dolores de cabeza..esto es lo que me muestra cuando ejecuto :
<html>

<head><title>413 Request Entity Too Large</title></head>

<body bgcolor="white">

<center><h1>413 Request Entity Too Large</h1></center>

<hr><center>nginx/1.1.19</center>

</body>

</html>

谢谢...

4

0 回答 0