Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.RuntimeException: General Error on signed upload with chunk_size option #148

Open
dimaportenko opened this issue Sep 21, 2022 · 26 comments
Assignees

Comments

@dimaportenko
Copy link

dimaportenko commented Sep 21, 2022

When the size of the uploading file is bigger then chunk_size option I'm getting the following error

java.lang.RuntimeException: General Error
at com.cloudinary.android.UploaderStrategy.callApi(UploaderStrategy.java:145)
at com.cloudinary.Uploader.callApi(Uploader.java:34)
at com.cloudinary.Uploader.uploadLargeParts(Uploader.java:218)
at com.cloudinary.Uploader.uploadLarge(Uploader.java:149)
at com.cloudinary.android.DefaultRequestProcessor.doProcess(DefaultRequestProcessor.java:223)
at com.cloudinary.android.DefaultRequestProcessor.processRequest(DefaultRequestProcessor.java:87)
at com.cloudinary.android.MediaManager.processRequest(MediaManager.java:441)
at com.cloudinary.android.AndroidJobStrategy$UploadJob.onRunJob(AndroidJobStrategy.java:264)
at com.evernote.android.job.Job.runJob(Job.java:124)
at com.evernote.android.job.JobExecutor$JobCallable.runJob(JobExecutor.java:183)
at com.evernote.android.job.JobExecutor$JobCallable.call(JobExecutor.java:168)
at com.evernote.android.job.JobExecutor$JobCallable.call(JobExecutor.java:151)

I'm using android SDK in this lib https://github.com/gosourcellc/react-native-cloudinary-sdk. Right now it uses 100mb chunk_size to overcome this issue.

@tommyg-cld
Copy link

Can you confirm you are using upload_large method which is required for files larger than 100MB, this method also lets you set the chunk size. See https://cloudinary.com/documentation/upload_images#chunked_asset_upload

@dimaportenko
Copy link
Author

I can confirm there is no such method upload_large. I searched for it but had no luck.

  • Here the link you send me
    CleanShot 2022-09-21 at 18 51 28@2x
  • here is android studio

CleanShot 2022-09-21 at 18 48 20@2x

here is sdk source code

@dimaportenko
Copy link
Author

@dimaportenko
Copy link
Author

Also, I'm using files less than 100MB.

@adimiz1
Copy link
Contributor

adimiz1 commented Sep 21, 2022

Hi @dimaportenko
Thank you very much for reporting this issue.
Can you please try to run your code with the following:
MediaManager.get().getCloudinary().uploader().uploadLarge(file, options)

@dimaportenko
Copy link
Author

Ok, I think I was able to do upload like this

try {
        Map resultData = MediaManager.get().getCloudinary().uploader().uploadLarge(file, options, new ProgressCallback() {
          @Override
          public void onProgress(long bytesUploaded, long totalBytes) {
                // ....
          }
        });
        promise.resolve(Utils.mapToWritableMap(resultData));
      } catch (IOException exception) {
        promise.reject(exception.getMessage());
      }

How can I get requesId here? I would like to be able to cancel https://cloudinary.com/documentation/android_image_and_video_upload#cancel_an_upload

MediaManager.get().cancelRequest(requestId);

@tommyg-cld
Copy link

Hi @dimaportenko , the request id should be included in the response header we send back.

Please let me know if you have any other questions or queries.

Kind Regards,
Thomas

@dimaportenko
Copy link
Author

@tommyg-cld can you share a code sample? Not sure how to use it. And I'm not able to find it in the documentation.

@tommyg-cld
Copy link

@dimaportenko so you will need to use the dispatch method and this should return the request id per https://cloudinary.com/documentation/android_image_and_video_upload#mediamanager_upload_method

e.g. String requestId = MediaManager.get().upload("imageFile.jpg").dispatch();

@dimaportenko
Copy link
Author

dimaportenko commented Sep 23, 2022

@tommyg-cld I'm completely confused. I'm using this one

String requestId = MediaManager.get().upload("imageFile.jpg").dispatch();

but I have the error, please see the first message of the thread. And you asked me to use https://cloudinary.com/documentation/upload_images#chunked_asset_upload which doesn't exist. Then @adimiz1 said I have to use

MediaManager.get().getCloudinary().uploader().uploadLarge(file, options)

It works for upload but there is no request Id. So I can't cancel it. Please help me, I don't understand

@tommyg-cld
Copy link

@dimaportenko apologies, that was just an example,

does the below work?

String requestId = MediaManager.get().getCloudinary().uploader().uploadLarge(file, options).dispatch();

@dimaportenko
Copy link
Author

Nope.
uploadLarge return Map and it hasn't dispatch method.

@dimaportenko
Copy link
Author

Also, this one isn't working for signed request

MediaManager.get().getCloudinary().uploader().uploadLarge(file, options)

@tommyg-cld
Copy link

@dimaportenko let me check internally with the team and will get back to you.

@dimaportenko
Copy link
Author

So I did more testing and I can confirm that unsigned upload works just fine. But signed request gives me a general error from the original message of this GitHub issue. It's same for

MediaManager.get().getCloudinary().uploader().uploadLarge(file, options)

The error message doesn't give any tips. Can you help me with what is wrong here?

java.lang.RuntimeException: General Error

@tommyg-cld
Copy link

@dimaportenko apologies for the delay in getting back.

So right now dispatch is not supported with upload_large, the request-id will only return when using the MediaManager object to upload. e.g.

MediaManager.get().upload("imageFile.jpg").dispatch();

We are checking further if we can support it.

Regarding the general error, please could you give us exactly how you sign your requests? I'm seeing a NoMethodError exception in our logs.

Also incase you didn't read it yet, here is how to setup signed upload: https://cloudinary.com/documentation/android_image_and_video_upload#signed_upload

@dimaportenko
Copy link
Author

  1. For dispatch, I'm doing the following
try {
        MediaManager.init(this.getReactApplicationContext(), new SignatureProvider() {
          @Override
          public Signature provideSignature(Map options) {
            return new Signature(
                    uploadParams.getString("signature"),
                    setupParams.getString("api_key"),
                    uploadParams.getInt("timestamp")
            );
          }

          @Override
          public String getName() {
            return null;
          }
        }, setupParams.toHashMap());
        promise.resolve(true);
      } catch (Exception e) {
        Log.e("CloudinarySdk", e.getMessage());
        promise.reject("CloudinarySdk", e.getMessage());
      }

It works fine if file size less then chunk_size. If file size is bigger then I'm getting General Error

  1. For cloudinary.uploader().uploadLarge above doesn't work. I'm getting api_key missing. So I have to add following to the options
      options.put("signature", uploadParams.getString("signature"));
    options.put("timestamp", uploadParams.getInt("timestamp"));
    options.put("api_key", setupParams.getString("api_key"));

And the same thing here I can upload just fine if the file size less then chunk_size. And I'm getting 'General Error' if bigger.

@tommyg-cld
Copy link

@dimaportenko we are taking a look so will get back asap.

@tamaracloudinary
Copy link

Hi @dimaportenko,

Can you please open a support ticket here: https://support.cloudinary.com/hc/en-us/requests/new with your cloud name and include more information on this?

This is what we know so far:

  1. You are trying to develop the SDK for React native using our Android SDK
  2. You are trying to upload a large file (less than 100 MB)
  3. You are trying to sign the request (please share with us how do you do that in your ticket).

In order for us to be able to reproduce the issue, we need every piece of information.
Once you open that ticket with more info, we will be able to escalate it internally.
Please confirm that what we understand is correct - that you try to create a React Native library using our Android SDK (this might be important for the solution).

We are waiting for your ticket,
Thanks a lot,
Tamara

@dimaportenko
Copy link
Author

Hi there, any updates?

@rnamba-cloudinary
Copy link

Hey @dimaportenko,

We're still waiting on news from the internal team. Could you follow up on a ticket for this issue so we can keep the line of communication open there?

@dimaportenko
Copy link
Author

We're still waiting on news from the internal team.

It's already a month passed already and no updates. It doesn't look like anybody working on this issue.

Could you follow up on a ticket for this issue so we can keep the line of communication open there?

I didn't get any updates there, doesn't look helpful to me.

@tamaracloudinary
Copy link

Hi @dimaportenko, I replied to the ticket you opened.
Let's continue this thread there.

@tommyg-cld tommyg-cld self-assigned this May 9, 2023
@tommyg-cld
Copy link

@dimaportenko just following up to see if this is still an issue? let me know if its ok to close out.

@dimaportenko
Copy link
Author

@tommyg-cld the issue is still the same. From internal support discussion, it's related to the callback_url and

The iOS SDK sends a header called X-Requested-With with the value XMLHttpRequest while the Android SDK does not. When using the callback parameter, that is only honoured for requests that aren't XHR-based (i.e. XMLHttpRequest). This is why the uploads redirect on Android but not on iOS. If the callback parameter was not being utilised then requests from both SDKs would not need to redirect as that won't be relevant anymore.

I suggest the following if you are going to add a solution like add header X-Requested-With with the value XMLHttpRequest to the Android SDK. then you can close after the change. In case you are not going to fix it you can also close it, so it will not bother you.

@tommyg-cld
Copy link

@dimaportenko thx for the update, yes we have an internal ticket to add header X-Requested-With with the value XMLHttpRequest to the Android SDK so we will keep you posted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants