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 AFNetworking
and how can i do this?
I went through the AFNetworking
documentation and there was a section called Creating an Upload Task for a Multi-Part Request, with Progress
. However, i am not able to upload the images that are in my NSMutableArray
.
**** NB: I want to upload the images in the NSMutableArray
as a Byte Array. How can i do this? ****
The code i have so far,
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
NSURL *URL = [NSURL URLWithString:@"site.com/upload"];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
Alamofire is nice source/library for the same:
Swift 4:
Common technique for turning a
UIImage
into NSData is with one of the following two methods.This of course assumes you know which type your image is. But since you used a
PickerController
to fetch the images, then it should be fairly easy to determine this. You just pull out the value under the keyUIImagePickerControllerReferenceURL
and check theext
parameter. This comment shows it visually https://stackoverflow.com/a/11506499/1529638.Try this.
}
Try this, I have uploaded 10 images on server using this code and its successfully uploaded on sever.
If you want to upload multiple images and you want to keep the parameter name same for all the images you do it as below :
In this way the files would be sent as array to the server.