Ios 当我尝试发送带有图像的Post请求时出错

Ios 当我尝试发送带有图像的Post请求时出错,ios,objective-c,post,Ios,Objective C,Post,当我试图发送带有图像的POST请求时,我遇到了这个错误 线程1:信号SiGABART 我认为这部分 [formData appendPartWithFileData:[NSData dataWithData:[self.images objectAtIndex:indexScroll]] name:@"FileUploadPost" fileName:@"image.jpg" mimeType:@"image/jpeg"]; 是什么导致了错误 - (IBAction)uploadPhoto:

当我试图发送带有图像的POST请求时,我遇到了这个错误

线程1:信号SiGABART

我认为这部分

[formData appendPartWithFileData:[NSData dataWithData:[self.images objectAtIndex:indexScroll]] name:@"FileUploadPost" fileName:@"image.jpg" mimeType:@"image/jpeg"]; 
是什么导致了错误

- (IBAction)uploadPhoto:(id)sender {
        AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
        manager.responseSerializer = [AFHTTPResponseSerializer new];

        NSDictionary *parameters = @{@"HI": @"Hello"};
        [manager POST:@"http://requestb.in/1c69jt31" parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        [formData appendPartWithFileData:[NSData dataWithData:[self.images objectAtIndex:indexScroll]] name:@"FileUploadPost" fileName:@"image.jpg" mimeType:@"image/jpeg"];

            [formData appendPartWithFileData:[self.images objectAtIndex:indexOfPage] name:@"FileUploadPost" fileName:@"image.jpg" mimeType:@"image/jpeg"];
        } success:^(AFHTTPRequestOperation *operation, id responseObject) {
            NSData * data = (NSData *)responseObject;
            NSLog(@"Success,Response string: %@", [NSString stringWithCString:[data bytes] encoding:NSISOLatin1StringEncoding]);
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            NSLog(@"Error: %@", error);
        }];

    }
-(iAction)上传照片:(id)发件人{
AFHTTPRequestOperationManager*manager=[AFHTTPRequestOperationManager];
manager.responseSerializer=[AFHTTPResponseSerializer new];
NSDictionary*参数=@{@“HI”:@“Hello”};
[经理职务:@”http://requestb.in/1c69jt31“参数:参数constructingBodyWithBlock:^(id formData){
[formData appendPartWithFileData:[NSData dataWithData:[self.images objectAtIndex:indexScroll]]名称:@“FileUploadPost”文件名:@“image.jpg”mimeType:@“image/jpeg”];
[formData appendPartWithFileData:[self.images objectAtIndex:indexOfPage]名称:@“FileUploadPost”文件名:@“image.jpg”mimeType:@“image/jpeg”];
}成功:^(AFHTTPRequestOperation*操作,id响应对象){
NSData*数据=(NSData*)响应对象;
NSLog(@“成功,响应字符串:%@,[NSString stringWithCString:[数据字节]编码:NSISOLATIN1STRINGCODING]);
}失败:^(AFHTTPRequestOperation*操作,NSError*错误){
NSLog(@“错误:%@”,错误);
}];
}

如果
self.images
UIImage
对象的数组,则必须使用类似于
uiimagejpegresentation
UIImagePNGRepresentation
的内容来提取该
UIImage
对象的
NSData

- (IBAction)uploadPhoto:(id)sender {
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer new];

    NSDictionary *parameters = @{@"HI": @"Hello"};
    [manager POST:@"http://requestb.in/1c69jt31" parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        [formData appendPartWithFileData:UIImageJPEGRepresentation(self.images[indexScroll], 0.8)] name:@"FileUploadPost" fileName:@"image.jpg" mimeType:@"image/jpeg"];
    } success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSData *responseString = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
        NSLog(@"Success,Response string: %@", responseString);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"Error: %@", error);
    }];
}
-(iAction)上传照片:(id)发件人{
AFHTTPRequestOperationManager*manager=[AFHTTPRequestOperationManager];
manager.responseSerializer=[AFHTTPResponseSerializer new];
NSDictionary*参数=@{@“HI”:@“Hello”};
[经理职务:@”http://requestb.in/1c69jt31“参数:参数constructingBodyWithBlock:^(id formData){
[formData appendPartWithFileData:UIImageJPEGresentation(self.images[indexScroll],0.8)]名称:@“FileUploadPost”文件名:@“image.jpg”mimeType:@“image/jpeg”];
}成功:^(AFHTTPRequestOperation*操作,id响应对象){
NSData*responseString=[[NSString alloc]initWithData:responseObject编码:NSUTF8StringEncoding];
NSLog(@“成功,响应字符串:%@”,响应字符串);
}失败:^(AFHTTPRequestOperation*操作,NSError*错误){
NSLog(@“错误:%@”,错误);
}];
}

@Rob我是这样做的图像=[dict objectForKey:UIImagePickerControllerOriginalImage];[self.images addObject:image]@Rob是的,我知道,但是有没有一种方法可以像我在上面尝试的那样上传特定的图像索引?因为这是我上传图像的唯一方法@Rob耶,现在你抓到我了!你知道如何通过索引获取UIImage吗?@Rob谢谢!你救了我,你能把你的评论作为一个完整的答案发表吗,这样我就可以接受你的解决方案了?顺便说一句,有时候你不需要将图像加载到数组中,只需要通过
UIImagePickerControllerReferenceURL
获取URL即可。然后,在构建此请求时,可以检索原始资产的数据,如下所示:。这是一个比你要问的更广泛的问题,但如果你开始发现内存问题,类似的方法可能会更有效。