Failed transformation
TomislavHorvat1 opened this issue · 1 comments
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
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:
- Check that you have imported the correct
Transformation
class from the Cloudinary SDK. It should becom.cloudinary.Transformation
. - Modify the
val transformation
declaration to remove the generic type parameter. Simply useval transformation = Transformation()
. - When setting the
TRANSFORMATION
option in the upload request, convert thetransformation
object to a string using thetoString()
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.