Skip to content
This repository was archived by the owner on Apr 18, 2026. It is now read-only.
This repository was archived by the owner on Apr 18, 2026. It is now read-only.

UploadMediaItem fails with cryptic error when the file length is zero #39

Description

@ylexus

When a file length is zero, uploading it causes this exception:

java.lang.IllegalArgumentException: The upload was completed but failed to finalize or get the result.
	at com.google.photos.library.v1.upload.PhotosLibraryUploadCallable.buildUploadMediaItemResponse(PhotosLibraryUploadCallable.java:314) ~[google-photos-library-client-1.5.0.jar:1.5.0]
	at com.google.photos.library.v1.upload.PhotosLibraryUploadCallable.call(PhotosLibraryUploadCallable.java:184) ~[google-photos-library-client-1.5.0.jar:1.5.0]
	at com.google.photos.library.v1.upload.PhotosLibraryUploadCallable.call(PhotosLibraryUploadCallable.java:45) ~[google-photos-library-client-1.5.0.jar:1.5.0]
	at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:?]
	at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source) ~[?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) ~[?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) ~[?:?]
	at java.lang.Thread.run(Unknown Source) ~[?:?]

I think PhotosLibraryUploadCallable should handle it better and fail fast with a more descriptive error.

Activity

  1. jfschmakeit commented on May 14, 2021

    @jfschmakeit
    Contributor

    The error is actually descriptive - the file was technically uploaded, but the Library API did not return a usable result (ie. an uploadToken). This could have different reasons , including an invalid file like in this case. Here the client library is mirroring the behaviour of the Library API itself and is passing through the response.

    However - I agree that it would be nicer to fail early, especially for something that would never succeed. I will propose a change to add a check for the file size before an upload request is made. Failing with a IOException in PhotosLibraryUploadCallable#call()looks like the best option.

  2. self-assigned this
    on May 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions