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

Start upload files display TransactionTooLargeException #554

Closed
EngKhAboshama opened this issue Dec 29, 2020 · 17 comments
Closed

Start upload files display TransactionTooLargeException #554

EngKhAboshama opened this issue Dec 29, 2020 · 17 comments

Comments

@EngKhAboshama
Copy link

Please can you give me information about how can I upload large files?

Caused by java.lang.RuntimeException: android.os.TransactionTooLargeException: data parcel size 10516560 bytes
at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1692)
at android.app.ContextImpl.startForegroundService(ContextImpl.java:1638)
at android.content.ContextWrapper.startForegroundService(ContextWrapper.java:688)
at net.gotev.uploadservice.extensions.ContextExtensionsKt.startNewUpload(ContextExtensions.kt:31)
at net.gotev.uploadservice.UploadRequest.startUpload(UploadRequest.kt:54)
at net.gotev.uploadservice.observer.request.RequestObserver.subscribe(RequestObserver.kt:52)
at net.gotev.uploadservice.UploadRequest.subscribe(UploadRequest.kt:82)

@gotev
Copy link
Owner

gotev commented Dec 29, 2020

Please can you post the code which generates this request?

@EngKhAboshama
Copy link
Author

I couldn't give you the request because It's a live crash on firebase. I checked the steps and I found that this happened when the user want to upload large files data, so does this question related to this issue
#342
?

@gotev
Copy link
Owner

gotev commented Dec 29, 2020

I couldn't give you the request because It's a live crash on firebase

But you have written the code which triggers that exception. The library has not any problem sending big files (recently I made a test with 2.2 GB file: #517 (comment)), so check how you are constructing the upload request. Bear in mind request parameters should not have big strings as values. TransactionTooLargeException is due to the Android Parcel size limitation.

@EngKhAboshama
Copy link
Author

EngKhAboshama commented Dec 29, 2020

I checked it, but the file is small size not a big one.
I checked the firebase crash and found that the "startForegroundService(intent)" causes exception inside lib class.

fun Context.startNewUpload(taskClass: Class, params: UploadTaskParameters): String {
val intent = Intent(this, UploadService::class.java).apply {
action = UploadServiceConfig.uploadAction
putExtra(taskClassKey, taskClass.name)
putExtra(taskParametersKey, params)
}

if (Build.VERSION.SDK_INT >= 26) {
    startForegroundService(intent)
} else {
    startService(intent)
}

return params.id

}

Android version 10

@EngKhAboshama
Copy link
Author

Please I don't handle this exception. This exception inside the lib in the code above "startForegroundService(intent)"

@gotev
Copy link
Owner

gotev commented Dec 29, 2020

@EngKhAboshama of course, because that's the point where the request gets validated, but the problem resides surely in how you are building the MultipartUploadRequest or BinaryUploadRequest and that's the relevant code.

@EngKhAboshama
Copy link
Author

EngKhAboshama commented Dec 29, 2020

@gotev My code is
MultipartUploadRequest(context, "${RetrofitClient.API_HOST}/documents") .setMethod("POST") .addParameter("subject_id", queryParams[2]) .addParameter("available_to_id", queryParams[3]) .addParameter("title", queryParams[1]) .addParameter("available_from", queryParams[5]) .addFileToUpload( queryParams[0], parameterName = "attachment", fileName = queryParams[1] ).setNotificationConfig(notificationConfigFactory) .subscribe(context, lifecycleOwner = lifecycleOwner, delegate = requestObserverDelegate)

So, what is the problem of my code?

@gotev
Copy link
Owner

gotev commented Dec 29, 2020

Check queryParams values length and also notificationConfigFactory. More specifically the icons set for the upload. Total size reported by Android in the exception is around 10MB:

Caused by java.lang.RuntimeException: android.os.TransactionTooLargeException: data parcel size 10516560 bytes

so it means the total size of the parameters exceeds the maximum allowed by the system. In this case the file size does not count as files are referenced only by path when building the request.

@gotev
Copy link
Owner

gotev commented Dec 29, 2020

Please also post Upload Service version used and please follow the issue template given next time, thanks 😉

@EngKhAboshama
Copy link
Author

@gotev Thank you very much. I found that the icon of the notification bitmap is a large one. I have to use the options parameter in the BitmapFactory.decodeResource() to decrease the size of the bitmap.

Sure, I will use it 👍

@EngKhAboshama
Copy link
Author

EngKhAboshama commented Dec 30, 2020

@gotev Please If I want to pass a bitmap with the lib, so can you provide me steps to do this?

@gotev
Copy link
Owner

gotev commented Dec 30, 2020

Save it to a temp file and then use its path

@EngKhAboshama
Copy link
Author

I'm using UploadNotificationStatusConfig class which inside the package package "net.gotev.uploadservice.data", so I have to customize the "NotificationHandler" class to use this way, isn't it?

@gotev
Copy link
Owner

gotev commented Dec 30, 2020

I thought I want to pass a bitmap with the lib meant uploading it to the server as a file. Then I haven't understood what do you mean.

@EngKhAboshama
Copy link
Author

EngKhAboshama commented Dec 30, 2020

Sorry for my last comment. If you check the following function
fun successConfig(context: Context): UploadNotificationStatusConfig { return UploadNotificationStatusConfig( title = context.getString(R.string.file_uploaded), message = context.getString(R.string.failed_upload), iconResourceID = R.drawable.ic_file_upload, ) }
so, I want to add the following line
largeIcon = BitmapFactory.decodeResource(context.resources, R.mipmap.ic_launcher_round)
, but the largeIcon is too large about 12MB, so You advise me to save the path of the bitmap. My question is how can I save the path? Shall I customize the "UploadNotificationStatusConfig" class to do this? or what?

Thank you in advance.

@gotev
Copy link
Owner

gotev commented Dec 31, 2020

Ok, so in that case the only advice I can give is to shrink your original icon resource using photoshop or similar program. It's not good to have such big assets in your app.

Closing this as it's not a library bug.

@gotev gotev closed this as completed Dec 31, 2020
Repository owner locked and limited conversation to collaborators Dec 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants