I'm developping an application that provides users with an interface where they can download files from our Google Cloud Storage. I wrote unit tests and I could connect to the storage and a file was downloaded.
Now that I'm (almost) finished with my interface, I wanted to test the whole application. But now I notice I don't really download the file, I download a file with META data about the file I want to download. Something like:
{
"kind": "storage#object",
"id": "xxxxxxxxxxx/Homer.png/xxxxxxxxxxxx",
"selfLink": "https://www.googleapis.com/storage/xxxxxxxxxxxxxxxx/Homer.png",
"name": "Homer.png",
"bucket": "xxxxxxxxxxxxxxx",
"generation": "xxxxxxxxxxxxxxx",
"metageneration": "1",
"contentType": "image/png",
"updated": "2014-07-17T08:37:28.026Z",
"storageClass": "STANDARD",
"size": "xxxxx",
"md5Hash": "xxxxxxxxxxxxxxxxxxxxx",
"mediaLink": "https://www.googleapis.com/download/storage/xxxxxxxxxxxxxxx/o/Homer.png?generation=xxxxxxxxxxxxxxxxx&alt=media",
"owner": {
"entity": "user-xxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"entityId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
"crc32c": "xxxxxxxxxx",
"etag": "xxxxxxxxxxxxx"
}
I'm wondering what I'm doing wrong, this is the code I'm using to download the file:
public byte[] getFileAsByteArray(String bucketName, String fileName)
throws GoogleAppManagerException {
Storage storage = null;
try {
storage = getStorage();
} catch (GeneralSecurityException e) {
throw new GoogleAppManagerException(SECURITY_EXCEPTION + e.getStackTrace(), e);
} catch (IOException e) {
throw new GoogleAppManagerException(IO_EXCEPTION + e.getStackTrace(), e);
}
Get get = null;
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
get = storage.objects().get(bucketName, fileName);
get.executeAndDownloadTo(outputStream);
} catch (IOException e1) {
throw new GoogleAppManagerException(IO_EXCEPTION + e1.getStackTrace(), e1);
}
return outputStream.toByteArray();
}