3

I am trying to upload a video to YouTube using the YouTube API. While running tests using unchanged code the following exception was thrown:

Exception in thread "main" java.lang.IllegalArgumentException: Cannot call getProgress() if the specified AbstractInputStreamContent has no content length. Use  getNumBytesUploaded() to denote progress instead.
at com.google.api.client.repackaged.com.google.common.base.Preconditions.checkArgument(Preconditions.java:92)
at com.google.api.client.util.Preconditions.checkArgument(Preconditions.java:49)
at com.google.api.client.googleapis.media.MediaHttpUploader.getProgress(MediaHttpUploader.java:934)
at com.google.api.services.samples.youtube.cmdline.UploadVideo$1.progressChanged(UploadVideo.java:151)
at com.google.api.client.googleapis.media.MediaHttpUploader.updateStateAndNotifyListener(MediaHttpUploader.java:907)
at com.google.api.client.googleapis.media.MediaHttpUploader.resumableUpload(MediaHttpUploader.java:471)
at com.google.api.client.googleapis.media.MediaHttpUploader.upload(MediaHttpUploader.java:336)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:427)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
at com.google.api.services.samples.youtube.cmdline.UploadVideo.main(UploadVideo.java:165)

Any idea why and how may I fix it?

1
  • 2
    Have you tried getNumBytesUploaded() instead of getProgress()? Commented Oct 27, 2015 at 16:00

2 Answers 2

1

Replace getProgress() to getNumBytesUploaded()

  System.out.println("Upload percentage: " + uploader.getNumBytesUploaded());

It Works you can upload large video.

Sign up to request clarification or add additional context in comments.

Comments

0

To get the progress using the getProgress() method, the API must be aware of the size of the file you are trying to upload, which you can set using inputStreamContent.setLength(file.getSize()).

Or you can simply use getNumBytesUploaded() as suggested.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.