cloudinary / cloudinary_ios

Cloudinary iOS SDK
MIT License
166 stars 106 forks source link

signedUpload not working at all (looks like not tested even once!) #66

Closed tapz closed 7 years ago

tapz commented 7 years ago

I get this error even when I set the api key to the Config and it's not empty. I'm using a signed upload.

Error Domain=com.cloudinary.error Code=400 "(null)" UserInfo={message=Missing required parameter - api_key}

let config = CLDConfiguration(cloudName: cloudName, apiKey: apiKey, secure: true)
self.cloudinary = CLDCloudinary(configuration: config)
self.uploader = cloudinary.createUploader()

let signature = CLDSignature(signature: signature, timestamp: NSNumber(value: timestamp))

let params = CLDUploadRequestParams()
params.setFolder(folder)
params.setSignature(signature)
params.setTransformation(transformation)
params.setUploadPreset(uploadPreset)
params.setResourceType(type)
...
self.uploader.signedUpload(
    url: self.scaledUrls[i],
    params: params,
    progress: { progress in
      ...
    },
    completionHandler: { result, error in
      ...
    })
tapz commented 7 years ago

Also, would be nice for the signature initializer to accept Int64 instead of NSNumber in Swift...

tapz commented 7 years ago

I modified CLDNetworkCoodinator and added the apiKey to signedRequestParams. Now the server does not respond with apiKey error anymore, but invalid signature.

CLDNetworkCoodinator.swift:

fileprivate func getSignedRequestParams(_ requestParams: CLDRequestParams) -> [String : Any] {
        var params: [String : Any] = requestParams.params
        if let signatureObj = requestParams.signature, 

-->             let apiKey = config.apiKey

 {
            params[CLDSignature.SignatureParam.Signature.rawValue] = signatureObj.signature
            params[CLDSignature.SignatureParam.Timestamp.rawValue] = signatureObj.timestamp

-->            params[CLDNetworkCoordinatorConsts.API_KEY] = apiKey

        }
        else if let apiSecret = config.apiSecret, let apiKey = config.apiKey {
            let timestamp = Int(Date().timeIntervalSince1970)
            params[CLDSignature.SignatureParam.Timestamp.rawValue] = cldParamValueAsString(value: timestamp)
            let signature = cloudinarySignParamsUsingSecret(params, cloudinaryApiSecret: apiSecret)
            params[CLDSignature.SignatureParam.Signature.rawValue] = signature
            params[CLDNetworkCoordinatorConsts.API_KEY] = apiKey
        }
        else {
            printLog(.error, text: "Must supply api key and secret for a signed request")
        }
        return params
    }
tapz commented 7 years ago

Turns out the signature timestamp is not added to the request at all! Only [String], String and Bool parameters are added. Did you try to use the signed requests even once before releasing the version 2 of the SDK??

CLDNetworkDelegate.swift

for key in parameters.keys {
    if let value = parameters[key], value is [String] {
    ...
    } else if let value = parameters[key] as? String {
    ...
    } else if let value = parameters[key] as? Bool {
    ..
    }
    SUPPORT FOR INT/INT64 PARAMETERS MISSING!
nadavofi commented 7 years ago

Hi Tapani, Thank you for pointing out these issues. We are looking into it and are working to resolve this as quick as possible. See #61 for momentary workaround for the signature issue.

taragano commented 7 years ago

This issue should be resolved by the latest release, v2.0.2. Please let us know if it works for you now?

taragano commented 7 years ago

Closing this issue due to the time elapsed. Please feel free to either re-open the issue, contact our support http://support.cloudinary.com or create a new ticket if you have any additional issues.