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
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).
Now if
chunkingis true and therefore the resumable upload is used the upload speed is fast (2 MB/s). But ifchunkingis 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.FileContentbutcom.google.api.client.http.InputStreamContentwith aBufferedInputStream: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