Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

erdinc27

macrumors regular
Original poster
Jul 20, 2011
168
1
i have two NSDictionary and i want to upload them to a server. I searched many examples but couldn't understand well. Is there anyone who has code or any good explained tutorial. here how my code looks
Code:
let dictInfo :NSMutableDictionary = NSMutableDictionary(objects: [MyConstants.theKey, MyConstants.theCommand], forKeys: ["key", "command"])

let theImage = self.imageView1.image!
let imageData = UIImageJPEGRepresentation(theImage, 0.6)
let dictImage : NSMutableDictionary = NSMutableDictionary(object: imageData!, forKey: "productImage")

I want to upload dictInfo and the dictImage.
 
Last edited by a moderator:
Do you have an API that accepts an image? There are a variety of ways to upload an image and it depends on what the API expects.
 
Do you have an API that accepts an image? There are a variety of ways to upload an image and it depends on what the API expects.
Actually the service i am working with that accepts image as form data and beside some more dictionary objects(e.g : name, surname, age etc). I can use that service with Objective C. Now i want to use it with Swift also. I tried something but couldnt create request body. I need help at that point.
 
Actually the service i am working with that accepts image as form data and beside some more dictionary objects(e.g : name, surname, age etc). I can use that service with Objective C. Now i want to use it with Swift also. I tried something but couldnt create request body. I need help at that point.

You can create a HTTPBody by using NSJSONSerialization and have it spit out NSData for you. But keep in mind that you need to structure your POST Request properly if it holds an image.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.