- 1. Create a Manager Object
- Afhttpsessionmanager *manager = [Afhttpsessionmanager manager];
- Manager. Responseserializer = [Afjsonresponseserializer serializer];
- Manager. Requestserializer = [Afjsonrequestserializer serializer];
- 2. Uploading Files
- Nsdictionary *dict = [nsdictionary dictionarywithobjectsandkeys:@ "Userheader.png", @ "Userheader", Nil Nil];
- [Manager Post:url parameters:dict constructingbodywithblock:^ (id<afmultipartformdata> _ Nonnull formData) {
- //Upload file Parameters
- [FormData appendpartwithfiledata:data Name:@ "Userheader" fileName:@ "Userheader.png" MimeType:@ "Image/jpeg"];
- } progress:^ (nsprogress * _nonnull uploadprogress) {
- //Print upload Progress
- CGFloat progress = 100. 0 * uploadprogress. completedunitcount/uploadprogress. Totalunitcount;
- DLog (@ "%.2lf%%", progress);
- } success:^ (nsurlsessiondatatask * _nonnull task, ID _nullable responseobject) {
- //Request succeeded
- DLog (@ "Request succeeded:%@", responseobject);
- } failure:^ (nsurlsessiondatatask * _nullable task, nserror * _nonnull error) {
- //Request failed
- DLog (@ "request failed:%@", error);
- }];
Two or more pictures
[OBJC]View PlainCopy
- 1. Create a Manager Object
- Afhttpsessionmanager *manager = [Afhttpsessionmanager manager];
- Manager. Responseserializer = [Afjsonresponseserializer serializer];
- Manager. Requestserializer = [Afjsonrequestserializer serializer];
- 2. Uploading Files
- Nsdictionary *dict = [nsdictionary dictionarywithobjectsandkeys:@ "Userheader.png", @ "Userheader", @ " Image.png ", @" image ", nil nil];
- [Manager Post:url parameters:dict constructingbodywithblock:^ (id<afmultipartformdata> _ Nonnull formData) {
- //Upload file Parameters
- [FormData appendpartwithfiledata:data1 Name:@ "Userheader" fileName:@ "Userheader.png" MimeType:@ "Image/jpeg"];
- [FormData appendpartwithfiledata:data2 Name:@ "image" fileName:@ "Image.png" MimeType:@ "Image/jpeg"];
- } progress:^ (nsprogress * _nonnull uploadprogress) {
- //Print upload Progress
- CGFloat progress = 100. 0 * uploadprogress. completedunitcount/uploadprogress. Totalunitcount;
- DLog (@ "%.2lf%%", progress);
- } success:^ (nsurlsessiondatatask * _nonnull task, ID _nullable responseobject) {
- //Request succeeded
- DLog (@ "Request succeeded:%@", responseobject);
- } failure:^ (nsurlsessiondatatask * _nullable task, nserror * _nonnull error) {
- //Request failed
- DLog (@ "request failed:%@", error);
- }];
iOS development using AFN upload images