1

I am having a tough time in implementing signed upload to Cloudinary using Kotlin. I have implemented my backend to provide me a signture and timestamp. This is what I have done to build the config:

var config = HashMap<String, Any> ()
        config.put("cloud_name", "my_cloud_name");
        //config.put("apiKey", my_api_key);
        config.put("use_filename", true);

Now, I am unable to do the MediaManager.init using the signature. Can anyone please help? The Java code says to do the below, but I am unable to reproduce the same in Kotlin:

MediaManager.init(this, new SignatureProvider() {
    @Override
    public Signature provideSignature(Map options) {
        // call server signature endpoint
    }
}, null);
1
  • 1
    You should provide a first solution and the error you’re seeing Commented Feb 22, 2018 at 6:45

2 Answers 2

2

This is how you intialize MediaManager with a signature provider in Kotlin:

MediaManager.init(thiscontext!!, object: SignatureProvider {
        override fun provideSignature(options: MutableMap<Any?, Any?>?): Signature {
            return myBackendConnector.signRequest(options)
        }

        override fun getName(): String {
            return "myCustomSignatureProvider"
        }

    }, config)

This will work assuming your backend already has the api key (it should), and that the return type from your connector is Signature. Otherwise you'll need to adapt your backend's result to Signature (populate the POJO with the result your server provided).

Sign up to request clarification or add additional context in comments.

1 Comment

Still facing issues with this
0

Get the timestamp and signature from your backend then add those as options.

val options = mapOf(
  "timestamp" to // timestamp from backend,
  "signature" to // signature from backend,
  // other options from backend
)
MediaManager.get()
            .upload(uri)
            .options(options)
            .callback(uploadCallback)
            .dispatch()

So this means not creating a SignatureProvider in the MediaManager.init().

I came to using this because I could not get this to work with the SignatureProvider in the MediaManager.init().

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.