So I'm trying to study up on HTTP/TCP/IP Protocols, Nodejs, MongoJS,and MongoDB all at once. So I'm trying to figure out a couple things with the Hapi Web Framework. I am able to communicate with the server with my iOS simulator however, I can't seem to parse the payload right. I understand I could use parameters in the URL to send the information but I would like to use the payload.
So I end up with this being saved into Mongo.
(
{
"_id" = 5431f161bb859872034d2456;
"{\"userLastNameKey\":\"Kwon\",\"userEmailKey\":\"email\",\"userFirstNameKey\":\"Michael\",\"userUsernameKey\":\"username\",\"userPasswordKey\":\"password\"}" = "";
},
{
"_id" = 5431fe5694ed4721046c1f8c;
"{\"userLastNameKey\":\"Kwon2\",\"userEmailKey\":\"email2\",\"userFirstNameKey\":\"Michael2\",\"userUsernameKey\":\"username2\",\"userPasswordKey\":\"password2\"}" = "";
This is my hapi code for the call.
// This will add a new user to the database
function addUser(request, response){
db.usersCollection.save(request.payload, function (err, saved){
if(err || !saved)
{
console.log("User not saved");
} else
{
console.log("User saved");
}
});
}
My end result I would like to try and get it to be like this
(
{
"_id" = 5431f161bb859872034d2456,
"userLastNameKey" = "Kwon",
"userEmailKey" = "email",
"userFirstNameKey"= "Michael",
"userUsernameKey" = "username",
"userPasswordKey" = "password",
}
)
Here's the iOS code
NSDictionary *userData = [User userToDictionary: newUserInfo];
NSData *userJSON = [NSJSONSerialization dataWithJSONObject: userData options: 0 error: nil];
NSURL *url = [NSURL URLWithString: urlString];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: url];
[request setHTTPMethod: #"POST"];
[request addValue: #"application/json" forHTTPHeaderField: #"Content-Type"];
// This will set up the url session
NSURLSessionConfiguration* config = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration: config];
NSURLSessionUploadTask *uploadTask = [session uploadTaskWithRequest: request fromData: userJSON completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if(error)
{
} else
{
}
}];
[uploadTask resume];
}
Anyone know how I can achieve this?
{
"_id" = 5431f161bb859872034d2456;
"userLastNameKey" = "Kwon";
"userEmailKey" = "email";
"userFirstNameKey"= "Michael";
"userUsernameKey" = "username";
"userPasswordKey" = "password";
}
That is NOT a JSON object. You need to use commas instead of semicolons. and colons instead of equals. Your ID is also not a decimal number so it's probably best to make it a string.
Your object would look like :
{
"_id" : "5431f161bb859872034d2456",
"userLastNameKey" : "Kwon",
"userEmailKey" : "email",
"userFirstNameKey" : "Michael",
"userUsernameKey" : "username",
"userPasswordKey" : "password"
}
To parse a (well-formatted) JSON string, use : var JSONObject = JSON.parse(JSONstring);
Related
Access paging in iOS Code from JSON previous and next link
In JSON object retrieved from graph api, due to loads of information the information is paged, when I try to access the previous and next link it gives OAuth error.
Can anyone help in how to access the link through objective C in iOS app.
I want to know two things - how to retrive 'N' items using --> limit=N
and how to open a FBSDKgraphrequest and using the paged link link (containing the paging information)
paging = {
next = "https://graph.facebook.com/v2.3/897401690298128/inbox?access_token=CAAEsxMhiSe4BACWnj27BT6ZBvj2BAxNZCtCNQyCKQORXyylXXkQy3DLSF75UGSz2FydAkQx6Pj49MOS0Q3SGiU1vkQ1iUEs2fQvvlwW3Wc04DEnXZB4CZCza7tOJfyncIPrkFrudQCeRhWUUREqMpCI8Dnm6Ozc6xmwOlT1uN2ZCgQ91llcVC1kV04fiZCqO6H6edFe2YZAUZBy86pw1p4SWCUvgMshzkvZBGgpG8UWG50ZCShdeQPUc86fsuQGOcAno0ZD&limit=25&until=1428241306&__paging_token=enc_AdC9127ZCBVnZACHUlMZBTC39ZC8bSP4ZA8uwQZBdy8xhsZAyKAcxxNdqn48Er3CrVM4DkJPATHhOYBVRm8FuCvYZBU8KSpZA";
previous = "https://graph.facebook.com/v2.3/897401690298128/inbox?access_token=CAAEsxMhiSe4BACWnj27BT6ZBvj2BAxNZCtCNQyCKQORXyylXXkQy3DLSF75UGSz2FydAkQx6Pj49MOS0Q3SGiU1vkQ1iUEs2fQvvlwW3Wc04DEnXZB4CZCza7tOJfyncIPrkFrudQCeRhWUUREqMpCI8Dnm6Ozc6xmwOlT1uN2ZCgQ91llcVC1kV04fiZCqO6H6edFe2YZAUZBy86pw1p4SWCUvgMshzkvZBGgpG8UWG50ZCShdeQPUc86fsuQGOcAno0ZD&limit=25&since=1432299972&__paging_token=enc_AdDp9ZCK2ZBP40AgTi4TCzaB0QFT1Cy7s1R7HLLDDaT7nbnLYDZB4LZBjiONOqG5QR9Q22KY1oU1LzNOwS5uNZBG7uLF4&__previous=1";
};
You can still use the SDK from Facebook, you only have to give the "after" field as a parameter. Then call a recursive function.
A solution I have just implemented in Swift:
func getFBTaggableFriends(nextCursor : String?, failureHandler: (error: NSError) -> Void) {
var qry : String = "me/taggable_friends"
var parameters = Dictionary<String, String>() as? Dictionary
if nextCursor == nil {
parameters = nil
} else {
parameters!["after"] = nextCursor
}
// Facebook: get taggable friends with pictures
var request = FBSDKGraphRequest(graphPath: qry, parameters: parameters)
request.startWithCompletionHandler { (connection : FBSDKGraphRequestConnection!, result : AnyObject!, error : NSError!) -> Void in
if ((error) != nil)
{
// Process error
println("Error: \(error)")
}
else
{
//println("fetched user: \(result)")
var resultdict = result as! NSDictionary
var data : NSArray = resultdict.objectForKey("data") as! NSArray
for i in 0..<data.count {
let valueDict : NSDictionary = data[i] as! NSDictionary
let id = valueDict.objectForKey("id") as! String
let name = valueDict.objectForKey("name") as! String
let pictureDict = valueDict.objectForKey("picture") as! NSDictionary
let pictureData = pictureDict.objectForKey("data") as! NSDictionary
let pictureURL = pictureData.objectForKey("url") as! String
println("Name: \(name)")
//println("ID: \(id)")
//println("URL: \(pictureURL)")
}
if let after = ((resultdict.objectForKey("paging") as? NSDictionary)?.objectForKey("cursors") as? NSDictionary)?.objectForKey("after") as? String {
self.getFBTaggableFriends(after, failureHandler: {(error) in
println("error")})
} else {
println("Can't read next!!!")
}
}
}
}
You will then call this function with:
getFBTaggableFriends(nil, failureHandler: {(error)
in println(error)});
Page information has the current access token, and also depending up different limits restriction paging values will always change , so; its best to use the url and fetch the result.
Because the result of next will also have pointer to both previous and next , best method to parse the result obtained is by calling it through a recursive function and passing the paging next values outside and inside the calling function to traverse all pages.
Don't forget to put a restriction where you want to stop traversing other nodes.
eg:
NSURL *url = [NSURL URLWithString:PagingNext];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *errorConnection)
{
if(errorConnection == nil)
{
NSError *error;
id result = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
if (result == nil)
{
NSLog(#"Error parsing JSON:\n%#",error.userInfo);
return;
}
//if no error then extract paging next and do what you want ->
/*
result = {
data[20],
paging={
previous= "URL_of_previous"
next = "URL_of_next"
}
}
*/
if ([result isKindOfClass:[NSDictionary class]])
{
NSArray * data = [result objectForKey:#"data"];
NSDictionary *paging =[result objectForKey:#"paging"];
NSString * resultPagingNext = [paging objectForKey:#"next"];
[self call_method_recursively_with_parameter_of_next_page:data pagingNext:resultPagingNext];
}
}
else
{
NSLog(#"Connection Error:\n%#", errorConnection.userInfo);
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:#"Network Issue"
message:#"Check if you are connected to Internet" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:#"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action)
{
NSLog(#"User has pressed OK."); }];
[alertController addAction:okAction];
[self presentViewController:alertController animated:YES completion:nil];
}
}];
//Save Dub to database
NSDictionary * dict = [NSDictionary dictionaryWithObjectsAndKeys:[DubsUtils dubUrlFromPath:trimmedDubPath], #"url", _sound, #"sound", nil];
if([NSJSONSerialization isValidJSONObject:dict])
{
NSLog(#"Valid ... %#", dict);
NSError *err;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&err];
NSLog(#"Done .. err : %# Data : %#",err,jsonData);
PFObject *data = [PFObject objectWithClassName:#"DubsData"];
data[#"dubs"] = dict;
[data saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (succeeded) {
// The object has been saved.
NSLog(#"New dub uploaded...");
} else {
NSLog(#"New dub Problem uploaded...");
// There was a problem, check error.description
}
}];
}
else
NSLog(#"Not Valid ... \n Detail : %# \n data : ",dict);
O/P : Not Valid ... Detail : {
sound = "sound : Hilarious Dolphin - url : dolphin.mp3 - category : Category n\U00b02 - name : Local Category 2 - lang : en";
url = "LMHFuxhDfUb9i2tm0Qryn67eZ4kH6n.mov"; }
i want to store this dict var object on parse server
I'm trying to parse information from a php, but i need to send a dictionary parameter so i try things ... i saw tutorials,examples but i'm stuck so i went back to the start: (What it's the good way for do this?)
func asd(){
let urlPath = "http://xxxxx.php"
let url: NSURL = NSURL(string: urlPath)
let request = NSMutableURLRequest(URL: url)
request.HTTPMethod = "GET"
var parm = ["id_xxxx": "900"] as Dictionary
//I THINK MY PROBLEM IT'S HERE! i dont know how to link parm with session, i try is with session.uploadTaskWithRequest(<#request: NSURLRequest?#>, fromData: <#NSData?#>) but doesn't work
let session = NSURLSession.sharedSession()
let task = session.dataTaskWithURL(url, completionHandler: {data, response, error -> Void in
println("Task completed")
if(error) {
// If there is an error in the web request, print it to the console
println(error.localizedDescription)
}
var err: NSError?
var jsonResult = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &err) as NSDictionary
if(err?) {
// If there is an error parsing JSON, print it to the console
println("JSON Error \(err!.localizedDescription)")
}
println(jsonResult.debugDescription)
let results: NSArray = jsonResult["x"] as NSArray
dispatch_async(dispatch_get_main_queue(), {
self.tableData = results
self.OfertaGridViewLista!.reloadData()
})
})
task.resume()
}
Thanks!
GET data needs to be part of the url's query string. Some methods will accept a dictionary of parameters for POST/PUT requests, but these methods will not add the dictionary to the url for you if you're using the GET method.
If you'd like to keep your GET parameters in a Dictionary for cleanliness or consistency, consider adding a method like the following to your project:
func buildQueryString(fromDictionary parameters: [String:String]) -> String {
var urlVars:[String] = []
for (k, value) in parameters {
let value = value as NSString
if let encodedValue = value.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed) {
urlVars.append(k + "=" + encodedValue)
}
}
return urlVars.isEmpty ? "" : "?" + urlVars.joined(separator: "&")
}
This method will take a dictionary of key/value pairs and return a string you can append to your url.
For example, if your API requests allow for multiple request methods (GET/POST/etc.) you'll only want to append this query string to your base api url for GET requests:
if (request.HTTPMethod == "GET") {
urlPath += buildQueryString(fromDictionary: parm)
}
If you're only making GET requests, there's no need to check for which method you'll be using to send your data.
Bit crazy that none of the answers here suggest using NSURLComponents and NSURLQueryItem objects. That is the safest and most modern way to do this.
var iTunesSearchURL = URLComponents(string: "https://itunes.apple.com/search")!
iTunesSearchURL.queryItems = [URLQueryItem(name: "term", value: trackName),
URLQueryItem(name: "entity", value: "song"),
URLQueryItem(name: "limit", value: "1")]
let finalURL = iTunesSearchURL.url
#paul-mengelt's answer in Objective C:
-(NSString *) buildQueryStringFromDictionary:(NSDictionary *)parameters {
NSString *urlVars = nil;
for (NSString *key in parameters) {
NSString *value = parameters[key];
value = [value stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];
urlVars = [NSString stringWithFormat:#"%#%#=%#", urlVars ? #"&": #"", key, value];
}
return [NSString stringWithFormat:#"%#%#", urlVars ? #"?" : #"", urlVars ? urlVars : #""];
}
Adapted for Swift 3
static func buildQueryString(fromDictionary parameters: [String:String]) -> String {
var urlVars:[String] = []
for (k,value) in parameters {
if let encodedValue = value.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed) {
urlVars.append(k + "=" + encodedValue)
}
}
return urlVars.isEmpty ? "" : "?" + urlVars.joined(separator: "&")
}
fixed objective C function
+(NSString *)buildQueryStringFromDictionary:(NSDictionary *)parameters
{
NSString *urlVars = #"";
for (NSString *key in parameters)
{
NSString *value = parameters[key];
value = [value stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];
urlVars = [NSString stringWithFormat:#"%#%#%#=%#", urlVars, urlVars.length ? #"&": #"", key, value];
}
return [NSString stringWithFormat:#"%#%#", urlVars ? #"?" : #"", urlVars ? urlVars : #""];
}
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"url_to_your_web_service.php/?key=%#",value]];
NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject];
NSURLSessionDataTask * dataTask = [defaultSession dataTaskWithURL:url
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if(error == nil){
NSString * text = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
NSLog(#"Data = %#",text);
}
}
}
];
[dataTask resume];
retrieve key's value inside your php:
$value=$_GET['key'];
In reading the documentation and sample code for posting objects, I must have missed something relating to serializing entities. It appears possible to send an entity to postObject and expect it to use the supplied mapping to produce JSON and POST it to a server.
I have been able to map and post an object, but the JSON is not coming through well formed.
I have been able to hand parameterize the object and get valid JSON. I'm about to dig into the source-code, but was wondering what I'm missing.
Here's the code and the results I'm seeing. Insight/help is appreciated!
I have the following Managed Object:
#interface TFUser : NSManagedObject
#property (nonatomic, retain) NSString * first_name;
#property (nonatomic, retain) NSString * last_name;
#end
I have the following code to map it:
+(RKEntityMapping *) mapping
{
if (_mapping == nil)
{
RKObjectManager *objectManager = [RKObjectManager sharedManager];
assert(objectManager && "Object manager not initialized!?");
RKManagedObjectStore *managedObjectStore = objectManager.managedObjectStore;
assert(objectManager && "No object store!?");
// USER Entity Map
_mapping = [RKEntityMapping mappingForEntityForName:#"TFUser"
inManagedObjectStore:managedObjectStore];
[_mapping addAttributeMappingsFromDictionary:#{
#"first_name": #"first_name",
#"last_name": #"last_name"
}];
_mapping.identificationAttributes = #[ #"first_name" ];
}
return _mapping;
}
I have the following code to test serializing one Managed Object directly:
TFUser *user = (TFUser*) [self.managedObjectContext insertNewObjectForEntityForName:#"TFUser"];
user.first_name = #"Mickey";
user.last_name = #"Mouse";
NSError *error;
RKRequestDescriptor *requestDescriptor =
[RKRequestDescriptor requestDescriptorWithMapping:[TFUser.mapping inverseMapping]
objectClass:[TFUser class]
rootKeyPath:#"user"
method:RKRequestMethodAny];
NSDictionary *parameters = [RKObjectParameterization parametersWithObject:user
requestDescriptor:requestDescriptor
error:&error];
NSData *jsonData= [RKMIMETypeSerialization dataFromObject:parameters MIMEType:RKMIMETypeJSON error:&error];
NSString *message = [[NSString alloc] initWithData:jsonData encoding:NSASCIIStringEncoding];
NSLog(#"USER JSON:\r\n%#", message);
And this produces what I'd expect:
USER JSON:
{
"user" : {
"first_name" : "Mickey",
"last_name" : "Mouse"
}
}
When I postObject the Managed Object directly:
[[RKObjectManager sharedManager] postObject:user
path:#"/user"
parameters:nil
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSLog(#"Success");
}
failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(#"Error");
}];
The server receives:
{ user: { first_name: 'Mickey', last_name: 'Mouse' } }
And the parser complains that it can't process the JSON.
Why am I getting a different result? How can I get the post to produce the correct JSON for the server?
Thanks!
- Kevin
The code has been working the entire time. The debugging and some code on the server was broken.
By carefully inspecting the logging of the body request being sent to the server it was apparent that the JSON was well-formed leaving the client. Here it is:
request.headers={
Accept = "application/json";
"Accept-Language" = "en;q=1, fr;q=0.9, de;q=0.8, zh-Hans;q=0.7, zh-Hant;q=0.6, ja;q=0.5";
"Content-Type" = "application/json; charset=utf-8";
"User-Agent" = "Treefort/1.0 (iPhone Simulator; iOS 7.0.3; Scale/2.00)";
}
request.body={
"user" : {
"first_name" : "Mickey",
"last_name" : "Mouse"
}
}
The code on the server was doing this:
console.log req.body
request = JSON.parse req.body
user = request.user
The JSON has already been processed into objects by the time it gets here. This means that the log line is dumping the object to the log, not the text of the received body. The second problem is that there is no reason to be explicitly requesting a JSON parse of the body. It's already been converted to objects.
To fix it I just changed the code to be:
user = req.body.user
Sometimes it helps to have somebody else say... it should be working. I've been banging my head on this for days. Thanks!
I am using RestKit 2.0 to send a core data entity and an image to a server with the 'multipartFormRequestWithObject' method. However, when the entity data arrives it is not in json format. If I send the entity using 'postObject' without an image then the data is in json format. I use the same RKObjectMapping for both situations.
What do I have to do to make the Object serialize to json? I tried
[request setValue:#"application/json" forHTTPHeaderField:#"content-type"];
But that didn't help and I already have my object manager settings as so:
[objectManager setRequestSerializationMIMEType:RKMIMETypeJSON];
[objectManager setAcceptHeaderWithMIMEType:RKMIMETypeJSON];
My Header Content-Type is multipart/form-data but I guess that is required.
request.headers={
Accept = "application/json";
"Accept-Language" = "en;q=1, fr;q=0.9, de;q=0.8, zh-Hans;q=0.7, zh-Hant;q=0.6, ja;q=0.5";
"Accept-Version" = 1;
"Content-Length" = 19014;
"Content-Type" = "multipart/form-data; boundary=Boundary+0xAbCdEfGbOuNdArY";
"User-Agent" = "app/1.0 (iPhone Simulator; iOS 7.0; Scale/2.00)";
}
My complete code is for the mapping and operation are below. As usual any feedback would be great. Thanks. Al
- (void)loginMainUser:(NSDictionary*)paramsDict path:(NSString *)apiPath{
RKObjectManager *manager = [RKObjectManager sharedManager];
// Response Mapping
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[self class]];
[mapping addAttributeMappingsFromDictionary:#{#"token" : #"token",
#"_links" : #"links"}];
[manager addResponseDescriptorsFromArray:#[[RKResponseDescriptor responseDescriptorWithMapping:mapping
method:RKRequestMethodAny
pathPattern:nil
keyPath:nil
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]]];
// Request Mapping
RKObjectMapping *userRequestMapping = [RKObjectMapping requestMapping];
[userRequestMapping addAttributeMappingsFromDictionary:#{#"name" : #"first_name",
#"surname" : #"last_name",
#"email" : #"email",
#"password" : #"password"}];
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:userRequestMapping
objectClass:[self class]
rootKeyPath:nil
method:RKRequestMethodAny];
[manager addRequestDescriptor:requestDescriptor];
UIImage *image = [UIImage imageNamed:#"logo.png"];
// Serialize the Article attributes then attach a file
NSMutableURLRequest *request = [manager multipartFormRequestWithObject:self
method:RKRequestMethodPOST
path:apiPath
parameters:nil
constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileData:UIImagePNGRepresentation(image)
name:#"logo"
fileName:#"logo.png"
mimeType:#"image/png"];
}];
RKObjectRequestOperation *operation = [manager objectRequestOperationWithRequest:request
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSLog(#"Success");
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(#"Failed");
}];
[manager enqueueObjectRequestOperation:operation];
}
multipartFormRequestWithObject is explicitly not JSON. This is by design. It's the HTTP content type that is changed so JSON and multipart form are mutually exclusive.
So, you need to change your mind about what you're trying to achieve.
One option could be to use a mapping operation to create the JSON for your object and then supply that JSON when you call multipartFormRequestWithObject. This would give you a multipart form message being sent with a section of JSON that could be deserialised on the server.
It is not the best approach but if you really need to get the JSON from a object with RestKit, you can convert it using this code:
// The object you want to convert
YourObject *object = ...;
// The RestKit descriptor that you want to use to map.
RKRequestDescriptor *requestDescriptorObject = ...;
NSDictionary *parametersForObject;
parametersForObject = [RKObjectParameterization parametersWithObject:object
requestDescriptor:requestDescriptorObject
error:nil];
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:parametersForObject
options:NSJSONWritingPrettyPrinted
error:nil];
NSString *jsonString;
if(jsonData) {
jsonString = [[NSString alloc] initWithData:jsonData
encoding:NSUTF8StringEncoding];
}
And then with the JSON string you can post it in a multi-part post. It can be done with any method, but as you have already RestKit, you can do it with the library.
For example, at the code of below there is a post of a file and the JSON string (in fact, the JSON data).
// The RestKit manager
RKObjectManager *manager = ...;
// The server endpoint
NSString *path = ...;
NSMutableURLRequest *request = [manager multipartFormRequestWithObject:nil method:RKRequestMethodPOST path:path parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
// Post of the file
[formData appendPartWithFileData:[NSData dataWithData:self.dataFile]
name:#"file"
fileName:filename
mimeType:mimetype];
// Post of the JSON data
[formData appendPartWithFormData:jsonData name:#"json_data"];
}];