Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Mobile Development
  3. iOS
  4. How to encode pdf file in UTF8 to for multipart http post

How to encode pdf file in UTF8 to for multipart http post

Scheduled Pinned Locked Moved iOS
1 Posts 1 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rdediana
    wrote on last edited by
    #1

    hello. i've had success using python in creating a multipart http post upload of a pdf file to a web service, however, i'm having a challenge achieving the same outcome with objectivec i'm using xcode 7.3 / iOS target version 9.3. when i look at the encoded file data within the python multipart POST it looks like the below. what would be the best process to load a PDF file from an IOS device and encode to UTF8 and submit an HTTP Multipart POST? the method i've crated is also listed below, however, the encoded file data does seem to be correct.

    - (void)submitPackageJSONv4:(NSDictionary*)json document:(NSData*)document {

    // prepare multipart boundary
    NSString \*boundary = @"unique-consistent-string";
    NSString \*contentType = \[NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary\];
    
    // ---- initialize request object ----
    NSMutableURLRequest \*request =
    \[\[NSMutableURLRequest alloc\] initWithURL:\[NSURL URLWithString:@"https://sandbox.esignlive.com/api/packages"\]\];
    \[request setHTTPMethod:@"POST"\];
    
    // ---- set headers ----
    \[request setValue:@"Basic enVyZ1A3Y.........eW94b0U4Tw==" forHTTPHeaderField: @"Authorization"\];
    \[request setValue:@"gzip, deflate" forHTTPHeaderField: @"Accept-Encoding"\];
    \[request setValue:@"\*/\*" forHTTPHeaderField: @"Accept"\];
    \[request setValue:@"keep-alive" forHTTPHeaderField: @"Connection"\];
    \[request setValue:@"chunked" forHTTPHeaderField: @"Transfer-Encodinge"\];
    \[request setValue:contentType forHTTPHeaderField: @"Content-Type"\];
    
    NSMutableData \*body = \[NSMutableData data\];
    
    // ---- apppend JSON ----
    \[body appendData:\[\[NSString stringWithFormat:@"--%@\\r\\n", boundary\] dataUsingEncoding:NSUTF8StringEncoding\]\];
    \[body appendData:\[\[NSString stringWithFormat:@"%@\\r\\n", @"Content-Disposition: form-data; name='payload'"\]
                      dataUsingEncoding:NSUTF8StringEncoding\]\];
    \[body appendData:\[NSKeyedArchiver archivedDataWithRootObject:json\]\];
    
    
    // ---- apppend docs ----
    \[body appendData:\[\[NSString stringWithFormat:@"--%@\\r\\n", boundary\] dataUsingEncoding:NSASCIIStringEncoding\]\];
    \[body appendData:\[\[NSString stringWithFormat:@"%@\\r\\n", @"Content-Disposition: form-data; name='file'; filename='file'"\]
                      dataUsingEncoding:NSUTF8StringEncoding\]\];
    
    \[body appendData:document\];
    \[body appendData:\[\[NSString stringWithFormat:@"--%@--\\r\\n", boundary\] dataUsingEncoding:NSUTF
    
    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups