1
votes

AndroidManifest.xml

 <meta-data
        android:name="CLOUDINARY_URL"
        android:value="${cloudinaryUrl}" />

In my activity that uploads the file I have init the MediaManager

MediaManager.init(this);

And I have uploaded the file using its uri by this:

val requestId = MediaManager.get().upload(uri).callback(object : UploadCallback {
    override fun onStart(requestId: String) {
        // your code here
    }

    override fun onProgress(requestId: String, bytes: Long, totalBytes: Long) {
        // example code starts here
        val progress = bytes.toDouble() / totalBytes
        // post progress to app UI (e.g. progress bar, notification)
        // example code ends here
    }

    override fun onSuccess(requestId: String, resultData: Map<*, *>) {
        // your code here
    }

    override fun onError(requestId: String, error: ErrorInfo) {
        // your code here
    }

    override fun onReschedule(requestId: String, error: ErrorInfo) {
        // your code here
    }
}).dispatch()

The problem is that I am getting an error 'Missing api key'. Do I need an api key for unsigned uploads?

1
Yes you need CLOUDINARY_URL for your implementation - sohel.eco
@sohel.eco I have added the CLOUDINARY_URL to the manifest meta-data. The error says about missing api_key. - ghita
Can you please give your exact error here ? - sohel.eco
"Must supply api_key" - full error description - ghita

1 Answers

1
votes

By looking here in the documentation. In the example you need to pass SignatureProvider

Example Code:

Map config = new HashMap();
config.put("cloud_name", "myCloudName");
MediaManager.init(this, new SignatureProvider(){
  @Override
  public Signature provideSignature(Map options) {
    // replace the following with a function that calls your backend signature generation endpoint
    SignResult res = signUpload(options);  // example name of a function that implements a synchronous HTTPS call
    return new Signature(res.getSignature(), res.getApiKey(), res.getTimestamp());
  }
  @Override
  public String getName() {
    return "SampleSignatureProvider"; // for logging purposes
  }
}, config);

To enable signed uploads you need to update your call to the MediaManager's init method with the name of an instance of your class (init(Context, SignatureProvider, Map)). Your class will be implemented whenever an upload must be signed.

See the SignatureProvider inteface

EDIT

For Unsigned upload you haven't mentioned .unsigned("sample_preset") with MediaManager.get().upload(uri). For more information see here