cloudinary_ios: Signed request error (timestamp=1)

I am trying to use Safe mobile request to upload image.

let config = CLDConfiguration(cloudName: request.cloudName, apiKey: request.apiKey, apiSecret: nil)
let cloudinary = CLDCloudinary(configuration: config)
let signature = CLDSignature(signature: request.signature, timestamp: NSNumber(value: request.timestamp))))
let params = CLDUploadRequestParams()
params.setSignature(signature)
params.setParam("api_key", value: request.apiKey)
params.setPublicId(request.publicId)
        
cloudinary.createUploader().signedUpload(data: data, params: params, progress: nil) { (result, error) in
    print(error)
}

And getting error: Invalid Signature <my signature>. String to sign - 'public_id=<my public id>&timestamp=1

As I can see, there is a problem with timestamp parameter sending. Because I create CLDSignature object with correct timestamp and signature.

But in CLDNetworkDelegate on multipart request forming the timestamp parameter is being recognized as Bool. And it turns to 1 instead of 1485214919, for example.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 25 (3 by maintainers)

Most upvoted comments

I re-created what I used to have so I can better explain to you 😃 Essentially you want to create the CLDUploadRequestParams using exactly the params that your server sends, with the addition that timestamp is a String rather than Int.

var paramsFromServer: [String: AnyObject] = ... // from your server

if let timestamp = params["timestamp"] as? Int {
    paramsFromServer["timestamp"] = timestamp.description as AnyObject
}

let params = CLDUploadRequestParams(params: paramsFromServer)

let configuration = CLDConfiguration(cloudName: ...)
let cloudinary = CLDCloudinary(configuration: configuration)
cloudinary.createUploader().upload(data: data, uploadPreset: "", params: params, completionHandler: ...)

This is my guess (under the Upload tab of Settings):

screen shot 2017-01-24 at 4 07 49 pm

Though it kind of sounds like Cloudinary is still not recognizing your upload as a “signed” upload. Did you set signature as a parameter?