Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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