Created
May 14, 2014 20:57
-
-
Save sburlot/cdfcbc6c64d2f0a8ac3c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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