iOS development using AFN upload images

Source: Internet
Author: User
Tags vars

  1. 1. Create a Manager Object
  2. Afhttpsessionmanager *manager = [Afhttpsessionmanager manager];
  3. Manager. Responseserializer = [Afjsonresponseserializer serializer];
  4. Manager. Requestserializer = [Afjsonrequestserializer serializer];
  5. 2. Uploading Files
  6. Nsdictionary *dict = [nsdictionary dictionarywithobjectsandkeys:@ "Userheader.png", @ "Userheader",   Nil Nil];
  7. [Manager Post:url parameters:dict constructingbodywithblock:^ (id<afmultipartformdata> _ Nonnull formData) {
  8. //Upload file Parameters
  9. [FormData appendpartwithfiledata:data Name:@ "Userheader" fileName:@ "Userheader.png"   MimeType:@ "Image/jpeg"];
  10. } progress:^ (nsprogress * _nonnull uploadprogress) {
  11. //Print upload Progress
  12. CGFloat progress = 100. 0 * uploadprogress. completedunitcount/uploadprogress. Totalunitcount;
  13. DLog (@ "%.2lf%%", progress);
  14. } success:^ (nsurlsessiondatatask * _nonnull task, ID _nullable responseobject) {
  15. //Request succeeded
  16. DLog (@ "Request succeeded:%@", responseobject);
  17. } failure:^ (nsurlsessiondatatask * _nullable task, nserror * _nonnull error) {
  18. //Request failed
  19. DLog (@ "request failed:%@", error);
  20. }];

Two or more pictures

[OBJC]View PlainCopy
  1. 1. Create a Manager Object
  2. Afhttpsessionmanager *manager = [Afhttpsessionmanager manager];
  3. Manager. Responseserializer = [Afjsonresponseserializer serializer];
  4. Manager. Requestserializer = [Afjsonrequestserializer serializer];
  5. 2. Uploading Files
  6. Nsdictionary *dict = [nsdictionary dictionarywithobjectsandkeys:@ "Userheader.png", @ "Userheader", @ "  Image.png ", @" image ", nil nil];
  7. [Manager Post:url parameters:dict constructingbodywithblock:^ (id<afmultipartformdata> _ Nonnull formData) {
  8. //Upload file Parameters
  9. [FormData appendpartwithfiledata:data1 Name:@ "Userheader" fileName:@ "Userheader.png"   MimeType:@ "Image/jpeg"];
  10. [FormData appendpartwithfiledata:data2 Name:@ "image" fileName:@ "Image.png"   MimeType:@ "Image/jpeg"];
  11. } progress:^ (nsprogress * _nonnull uploadprogress) {
  12. //Print upload Progress
  13. CGFloat progress = 100. 0 * uploadprogress. completedunitcount/uploadprogress. Totalunitcount;
  14. DLog (@ "%.2lf%%", progress);
  15. } success:^ (nsurlsessiondatatask * _nonnull task, ID _nullable responseobject) {
  16. //Request succeeded
  17. DLog (@ "Request succeeded:%@", responseobject);
  18. } failure:^ (nsurlsessiondatatask * _nullable task, nserror * _nonnull error) {
  19. //Request failed
  20. DLog (@ "request failed:%@", error);
  21. }];

iOS development using AFN upload images

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.