Upload multiple images using AFNetworking

前端 未结 5 974
别跟我提以往
别跟我提以往 2020-12-19 12:30

I used the PickerController and loaded a few images on to a NSMutableArray.

Now i need to upload all of these images at once. am using

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-19 13:11

    -(void)uploadImages{
    
    // image.finalImage - is image itself
    // totalCount - Total number of images need to upload on server
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    NSDictionary *parameters = @{@"Key":@"Value",@"Key":@"Value"};
    [manager POST:serverURL parameters:parameters constructingBodyWithBlock:^(id formData) {
        [formData appendPartWithFileData:UIImagePNGRepresentation(image.finalImage) name:@"ImageName" fileName:[[Helper getRandomString:8] stringByAppendingString:@".png"] mimeType:@"image/png"];
    } success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *jsonResponse = [NSJSONSerialization JSONObjectWithData:(NSData *)responseObject options:kNilOptions error:nil];
        _uploadCounter+=1;
        if(_uploadCounter

    }

    Try this, I have uploaded 10 images on server using this code and its successfully uploaded on sever.

提交回复
热议问题