func UploadImageWithDict(#Dict : NSMutableDictionary ,Image : UIImage) -> NSMutableDictionary
{
var imageData = UIImageJPEGRepresentation(Image,0.1)
if (imageData != nil)
{
var request = NSMutableURLRequest(URL: NSURL(string:””)!)
var boundary = NSString(format: "---------------------------14737809831466499882746641449")
request.addValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
let body = NSMutableData.alloc()
var postData:String = String()
postData += "--\(boundary)\r\n"
for (key, value : AnyObject) in Dict {
if let value = value as? String {
postData += "--\(boundary)\r\n"
postData += "Content-Disposition: form-data; name=\"\(key)\"\r\n\r\n"
postData += "\(value)\r\n"
}
}
postData += "--\(boundary)\r\n"
postData += "Content-Disposition: form-data; name=\"photo\"; filename=\"\(Int64(NSDate().timeIntervalSince1970*1000)).jpg\"\r\n"
postData += "Content-Type: image/jpeg\r\n\r\n"
body.appendData(postData.dataUsingEncoding(NSUTF8StringEncoding)!)
body.appendData(imageData)
postData = String()
postData += "\r\n"
postData += "\r\n--\(boundary)--\r\n"
body.appendData(postData.dataUsingEncoding(NSUTF8StringEncoding)!)
request.HTTPMethod = "POST"
request.HTTPBody = body
var Err: AutoreleasingUnsafeMutablePointer<NSError? > = nil
var returnData: NSData? = NSURLConnection.sendSynchronousRequest(request, returningResponse:nil , error:Err)
if(Err == nil && returnData != nil)
{
print(">>>>>>>>>")
var returnString = NSString(data: returnData!, encoding: NSUTF8StringEncoding)
var data : NSData? = StringData.dataUsingEncoding(NSUTF8StringEncoding)
var dict : AnyObject? = NSJSONSerialization.JSONObjectWithData(data!,options:NSJSONReadingOptions.AllowFragments, error: nil)
print(dict)
return dict as! NSMutableDictionary
}
else
{
return NSMutableDictionary()
}
}
else
{
return NSMutableDictionary()
}
}