Skip to content

Instantly share code, notes, and snippets.

@sburlot
Created May 14, 2014 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sburlot/cdfcbc6c64d2f0a8ac3c to your computer and use it in GitHub Desktop.
Save sburlot/cdfcbc6c64d2f0a8ac3c to your computer and use it in GitHub Desktop.
STHTTPRequest* r = [STHTTPRequest requestWithURLString:POST_CONTRACT_URL];
NSDictionary *dataToEncode = @{@"key0": @"object",
// other data...
@"key1": @"object"};
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:dataToEncode
options:NSJSONWritingPrettyPrinted
error:&writeError];
NSString* jsonString = [[NSString alloc] initWithData:jsonData
encoding:NSUTF8StringEncoding];
r.POSTDictionary = @{ @"data" : jsonString };
r.encodePOSTDictionary = NO;
[r setUsername:USERNAME
password:PASSWORD];
r.completionBlock = ^(NSDictionary *headers, NSString *body) {
// Handle success
};
r.errorBlock = ^(NSError *error) {
// Handle Error
};
NSString* filePath = @"path/to/file";
[r addFileToUpload:filePath
parameterName:@"pics_1"];
for (int i = 0; i < [signatureFiles count]; i++) {
NSString* filePath = @"path/to/file";
UIImage* image = [[UIImage imageWithContentsOfFile:filePath] imageScaledToFitSize:CGSizeMake(320.0f, 240.f)];
[r addDataToUpload:UIImageJPEGRepresentation(image, 0.7)
parameterName:[NSString stringWithFormat:@"pics_%d", i + 2]
mimeType:@"application/octet-stream"
fileName:[NSString stringWithFormat:@"%@.jpg", [signatureFiles objectAtIndex:i]]];
}
[r startAsynchronous];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment