0

I tried to upload an image from iPhone application developped in Swift to Cloudinary API using NSMutableURLRequest and POST method. The Cloudinary API response is : responseString = Optional(<h2>Incomplete response received from application</h2>).

My function's code :

    //
    // Upload a picture to cloudinary
    //
    static func uploadPicture(imageData: NSData?, api_key: String, timestamp: String, signature: String) {

        let request = NSMutableURLRequest(URL: NSURL(string: "https://api.cloudinary.com")!)
        request.HTTPMethod = "POST"
        let bodyData = "\(imageData), \(api_key), \(timestamp), \(signature)"
        request.HTTPBody = bodyData.dataUsingEncoding(NSUTF8StringEncoding);

        let task = NSURLSession.sharedSession().dataTaskWithRequest(request) { data, response, error in
            guard error == nil && data != nil else {
                print("error=\(error)")
                return
            }

            if let httpStatus = response as? NSHTTPURLResponse where httpStatus.statusCode != 200 {
                print("statusCode should be 200, but is \(httpStatus.statusCode)")
                print("response = \(response)")
            }

            let responseString = NSString(data: data!, encoding: NSUTF8StringEncoding)
            print("responseString = \(responseString)")
        }
        task.resume()
    }
Dorian Richard
  • 41
  • 1
  • 1
  • 5
  • Make sure you follow the guidelines of uploading to Cloudinary (endpoint, parameters name-conventions, data encoding, etc): http://cloudinary.com/documentation/image_upload_api_reference#upload Also, why aren't you using the [official iOS libraries](https://github.com/cloudinary/cloudinary_ios)? – Nadav Ofir May 26 '16 at 18:10
  • The official iOS library is outdated and looks not well maintained. Issues are quite scaring. – Tom Jun 22 '16 at 06:36
  • Just check this SO answer : http://stackoverflow.com/a/26747857/3668376. It worked well for me. – Tom Jun 22 '16 at 06:46

0 Answers0