How to encode pdf file in UTF8 to for multipart http post
iOS
1
Posts
1
Posters
3
Views
1
Watching
-
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