I'm writing an Android app and want to use Google Cloud Storage for storing potentially large-ish media files. I'm using the Java client library for the JSON API: com.google.api.services.storage.
My problem is performance. I'm sure I must be doing something wrong. I've got file uploads working but it's almost comically slow. It takes approximately 5 minutes to transfer a 1.5 MB image file, so that's something like 5 kbps, which is going to be unusable for my app. I've enabled billing for my app, but I am on the free tier. Surely this isn't the expected performance level? I'm testing this on a Galaxy S4 on broadband wifi. I am using a Service Account OAUth client key to access GCS.
I've tried with and without gzip encoding, and with and without direct (non-resumable) uploads, and with different chunk sizes - default, minimum, multiples of minimum, etc. I get similar results in all cases. Here's my upload function:
public void uploadFile(String bucketName, String filePath, String mimeType, String gcsFilename, IOProgress ioProgress)
throws IOException {
StorageObject object = new StorageObject();
object.setBucket(bucketName);
File file = new File(filePath);
Long fileSize = file.length();
Log.d(TAG, "uploadFile START: " + bucketName + ":" + gcsFilename + " -> " + filePath);
try (InputStream stream = new FileInputStream(file)) {
InputStreamContent content = new InputStreamContent(mimeType,
stream);
Storage.Objects.Insert insert = storage.objects().insert(
bucketName, null, content);
insert.setName(gcsFilename);
insert.getMediaHttpUploader().setDisableGZipContent(true); // this seems to help to disable... at least when debugging
// insert.getMediaHttpUploader().setDirectUploadEnabled(true);
insert.getMediaHttpUploader().setChunkSize(MediaHttpUploader.MINIMUM_CHUNK_SIZE);
if (ioProgress != null) {
insert.getMediaHttpUploader().setProgressListener(new CloudUploadProgressListener(ioProgress, fileSize));
}
insert.execute();
Log.d(TAG, "uploadFile FINISH: " + bucketName + ":" + gcsFilename + " -> " + filePath);
}
}