Skip to content

Direct upload with FileContent is very slow (YouTube Data API v3) #925

@DanielRaapDev

Description

@DanielRaapDev

I used the following code to transfer videos to YouTube. Because the proxy does not support chunking we cannot use the resumable upload method (which also works fine in local tests).

File videoFile = getVideoFile();
AbstractInputStreamContent videoContent = new FileContent(mimeType, videoFile);

Videos.Insert insert = service.videos().insert(EDITED_PARTS, newVideo, videoContent);
MediaHttpUploader uploader = insert.getMediaHttpUploader();
uploader.setDirectUploadEnabled(!chunking);

insert.execute();

Now if chunking is true and therefore the resumable upload is used the upload speed is fast (2 MB/s). But if chunking is false and direct upload is used the upload is extremely slow (20 kB/s). We use java.net for transport.
So I tried to debug this problem with the system property "javax.net.debug=all". And this helped a lot! It showed that always a single byte of plain text was encrypted and 25 bytes SSL were transfered over the wire via HTTPS. So obviously no buffer is used to read the file.
My solution is to not use com.google.api.client.http.FileContent but com.google.api.client.http.InputStreamContent with a BufferedInputStream:

InputStream videoStream = new BufferedInputStream(new FileInputStream(videoFile));
AbstractInputStreamContent videoContent = new InputStreamContent(mimeType, videoStream).setLength(videoFile.length());

Would be nice if this bug can be fixed in this library.

Used versions (in pom.xml):
google-api-services-youtube v3-rev125-1.19.1
google-api-client 1.19.1
google-http-client-jackson2 1.19.0
google-http-client 1.19.0

Metadata

Metadata

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions