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

Failed transformation #153

Open
TomislavHorvat1 opened this issue Jun 16, 2023 · 1 comment
Open

Failed transformation #153

TomislavHorvat1 opened this issue Jun 16, 2023 · 1 comment

Comments

@TomislavHorvat1
Copy link

Describe the bug in a sentence or two.

I get an java.lang.ClassCastException: com.cloudinary.Transformation cannot be cast to java.lang.String error when attempting a transformation:
val transformation = Transformation<Transformation<*>>().width(1280).crop("scale")

Issue Type (Can be multiple)

[ ] Build - Can’t install or import the SDK
[ ] Performance - Performance issues
[x] Behaviour - Functions aren’t working as expected (Such as generate URL)
[x] Documentation - Inconsistency between the docs and behaviour
[ ] Other (Specify)

Steps to reproduce

val transformation = Transformation<Transformation<*>>().width(1280)
        MediaManager.get().upload(uri)
            .option(TRANSFORMATION, transformation)
            .option(SIGNATURE, photoSignature.signature)
            .option(TIMESTAMP, photoSignature.timestamp)
            .option(PUBLIC_ID, photoSignature.publicId)
            .option(TAG, tag)
            .callback(object : UploadCallback {
                override fun onStart(requestId: String?) {
                    callback.onStart()
                }

                override fun onProgress(requestId: String?, bytes: Long, totalBytes: Long) {
                    callback.onProgress(bytes = bytes, totalBytes = totalBytes)
                }

                override fun onSuccess(requestId: String?, resultData: MutableMap<Any?, Any?>?) {
                    callback.onSuccess(resultData)
                }

                override fun onError(requestId: String?, error: ErrorInfo?) {
                    callback.onError(Throwable("CODE ${error?.code}: ${error?.description}"))
                }

                override fun onReschedule(requestId: String?, error: ErrorInfo?) {
                    callback.onError(Throwable("CODE ${error?.code}: ${error?.description}"))
                }
            })
            .dispatch()

Error screenshots or Stack Trace (if applicable)

java.lang.ClassCastException: com.cloudinary.Transformation cannot be cast to java.lang.String at com.cloudinary.Util.buildUploadParams(Util.java:63) at com.cloudinary.Uploader.buildUploadParams(Uploader.java:51) at com.cloudinary.Uploader.uploadLargeParts(Uploader.java:160) 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.doWork(AndroidJobStrategy.java:163) at androidx.work.Worker$1.run(Worker.java:86) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637) at java.lang.Thread.run(Thread.java:1012)

Build System

[ ] Maven
[x] Gradle
[ ] Other (Specify)

Is the issue reproducible only on a specific device?

[x] No
[ ] Yes (specify model + Android version + vendor build number, if applicable)

Versions and Libraries (fill in the version numbers)

Cloudinary Android SDK version 2.3.1
Android version - 33
Kotlin version - 1.8.10
JVM (of the dev environment) - 17
Gradle - 8.0

@tamaracloudinary
Copy link

Hi there @TomislavHorvat1, the error you're encountering indicates that there is a type mismatch when passing the Transformation object as an option in the Cloudinary upload request.

To resolve this issue, you can try the following steps:

  1. Check that you have imported the correct Transformation class from the Cloudinary SDK. It should be com.cloudinary.Transformation.
  2. Modify the val transformation declaration to remove the generic type parameter. Simply use val transformation = Transformation().
  3. When setting the TRANSFORMATION option in the upload request, convert the transformation object to a string using the toString() method. Update the option line as follows:
    .option(TRANSFORMATION, transformation.toString())
    

Here's the updated code snippet for reference:

val transformation = Transformation()
MediaManager.get().upload(uri)
    .option(TRANSFORMATION, transformation.toString())
    .option(SIGNATURE, photoSignature.signature)
    .option(TIMESTAMP, photoSignature.timestamp)
    .option(PUBLIC_ID, photoSignature.publicId)
    .option(TAG, tag)
    .callback(object : UploadCallback {
        // ...
    })
    .dispatch()

Please give this a try, and let me know if you encounter any further issues.

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

2 participants