Trying to download file in Google Storage return json

Im trying to download a file from Google Storage. If I access Google Storage page, I can download the file correctly.

But if I try to use an api to download, its returning an json object:

 {
    "kind": "storage#object",
    "id": "storage-key/file/id",
    "selfLink": "link",
    "name": "name.xlsx",
    "bucket": "bucketName",
    "generation": "35452344234",
    "metageneration": "1",
    "contentType": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
    "timeCreated": "2017-02-23T12:35:04.258Z",
    "updated": "2017-02-23T12:35:04.258Z",
    "storageClass": "STANDARD",
    "timeStorageClassUpdated": "2017-02-23T12:35:04.258Z",
    "size": "4679",
    "md5Hash": "k3A546723454afhjgrfKuZw==",
    "mediaLink": "medialink",
    "crc32c": "U2ajDQ==",
    "etag": "DMiAt62dbtICAAE="
}

I'm basicly using:

import com.google.api.services.storage.Storage;
storage.objects().get(bucketName, fileName).executeAsInputStream();

And yesterday it worked :. Do you have any ideia of why its returning a json?

Upvotes: 0

Views: 402

Answers (1)

Brandon Yarbrough
Brandon Yarbrough

Reputation: 38379

executeAsInputStream() retrieves the object's metadata (as a stream).

executeMediaAsInputStream() retrieves the object's contents (as a stream).

Also, you may be interested in switching to the new google-cloud client library for Java, which removes some of the more confusing bits of the client you're using. Here's an example of how to use it for downloading.

Upvotes: 1

Related Questions