cloudinary/cloudinary_android

Question: How do I download files and save them to the file system?

robingenz opened this issue · 2 comments

I want to download a file from Cloudinary using the Android SDK and save it to the local file system.

On iOS I use the following method for this:

self.cloudinary?.createDownloader().fetchAsset(url) { (progress) in
    print(progress.fractionCompleted)
} completionHandler: { (asset, error) in
    if let error = error {
        completion(nil, error.description)
        return
    }
    completion(asset, nil) // Now i can write the asset to the filesystem
}

How does this work on Android?

I could not find any documentation on this. I had the following approach:

DownloadRequestBuilder request = MediaManager.get().download(plugin.getContext()).load(url);
request.callback(new DownloadRequestCallback() {
      @Override
      public void onSuccess() {
          callback.success(asset); // <-- Where do I get the asset?
      }

      @Override
      public void onFailure(Throwable t) {
          callback.error(t.getMessage());
      }
});

Unfortunately, I don't get the file data this way and also the following error message: Must set a factory before downloading.

Hi @robingenz,
Thanks for contacting us.
Can you please let me know if you implemented the Cloudinary download adapter as explained here: https://cloudinary.com/documentation/android_image_manipulation#cloudinary_download_adapter?
Looking forward to your updates,
Thanks

I must have missed that. I was able to solve the problem in the meantime with the Android DownloadManager. For this reason i am closing this issue now.

Anyway, thanks for your help!