捕获上传图像失败的iOS

时间:2015-02-07 07:55:49

标签: ios uiimage uiimagepickercontroller afnetworking-2

我试图通过AFNetworking上传图片。 以下是我尝试在阵列中保存图像的方法。图片上传开始,但在上传1.1%后立即停止上传,没有任何错误。不知道发生了什么。

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

 [picker dismissViewControllerAnimated:YES completion:nil];

UIImage *chosenImage = info[UIImagePickerControllerOriginalImage];
NSData *imageData=UIImagePNGRepresentation(chosenImage);

ImageObject *imageObject=[[ImageObject alloc]init];

imageObject.image=chosenImage;
imageObject.imageData=imageData;
imageObject.imageUploadStatus=FALSE;
imageObject.isUploaded=FALSE;
[imageObject setDescription:@""];

[imageDataArray addObject:imageObject];
}

在此之后,我使用以下方法上传图像。

-(void)uploadPicturesAndVides:(NSMutableArray *)_list descriptions:(NSMutableArray *)_description categoryID:(NSString *)_catID categoryName:(NSString *)_categoryName index:(NSInteger)_index{
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.requestSerializer = [AFHTTPRequestSerializer serializer];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
[manager.requestSerializer setValue:[SettingValues getRSFToken] forHTTPHeaderField:@"_csrf"];
[manager.requestSerializer setValue:@"USER_Agent_Value" forHTTPHeaderField:@"User-Agent"];
NSString *imageUrl;
imageUrl=[NSString stringWithFormat:@"%@/user/upload/photo",BASE_SERVER_ADDRESS];
NSMutableArray *tempArray=[[NSMutableArray alloc] init];
for (ImageObject *object in _list) {
    [tempArray addObject:[object description]];
}
NSString *descriptions;
descriptions=[tempArray componentsJoinedByString:@","];

NSDictionary *parameters = @{@"descriptionImage":descriptions,@"subcategoryId":_catID,@"subcategoryName":_categoryName,@"_csrf": [SettingValues getRSFToken]};

AFHTTPRequestOperation *op =    [manager POST:imageUrl parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {

    NSInteger count=_index;
    for (ImageObject *object in _list) {
        NSString *imageName = [NSString stringWithFormat:@"IMG00%zd.png",count];
        [formData appendPartWithFileData:object.imageData name:@"files" fileName:imageName mimeType:@"image/png"];
    }

} success:^(AFHTTPRequestOperation *operation, id responseObject) {
    [SettingValues setImageUploadStatus:TRUE];
    [self uploadingRequestSuccessfulWithObject:responseObject reqestName:@"picture" index:_index];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
}];
[op setUploadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
    double percentDone = (double)totalBytesWritten / (double)totalBytesExpectedToWrite;
    [self goBackTouploadingControllerWithProgressResult:percentDone index:_index];
}];
cancelManager=op;
[op start];
}

以下是图片及其进度留在这里!没有成功没有失败。 :( enter image description here

问题是当我通过相机胶卷上传图像时代码有效,但是当我捕捉图像时,它没有。 我在进度块中放了NSLog(@"progress updated(percentDone) : %f", percentDone);,我找到了以下日志

2015-02-07 13:07:22.854 APP_Name[2069:60b] progress updated(percentDone) : 0.002105
2015-02-07 13:07:22.858 APP_Name[2069:60b] progress updated(percentDone) : 0.004210
2015-02-07 13:07:22.860 APP_Name[2069:60b] progress updated(percentDone) : 0.006315
2015-02-07 13:07:22.861 APP_Name[2069:60b] progress updated(percentDone) : 0.008413

然后每件事都停止了。 在Failure块中我放下了以下日志  NSLog(@“错误:%@ *****%@”,operation.responseString,错误); 从未执行过:(

0 个答案:

没有答案