0

Google's official doc tells us :

 The download URL for files looks something like this:
 https://doc-04-20-docs.googleusercontent.com/docs/secure/m7an0emtau/WJm12345/YzI2Y2ExYWVm?h=16655626&e=download&gd=true

And it also tells us that a document entry xml is done like following :

<entry ...
...
<content type='application/zip' src='https://doc-0s-84-docs.googleusercontent.com/docs/securesc/4t...626&amp;e=download&amp;gd=true'/>
...
</entry>

But whatever I try with gdata java client library, I don't manage to retrieve that url. I tried all the .get*Link*() methods, and .getContent(). Does somebody met this issue and found the solution ? I've also tried to get the mediasource and work on its input stream.

The finality of that is to get the file's content (the file is binary with a custom format) back on my java application server (GAE) to send it to my client who can parse it and view it.

Cheers,

Ricola3D

Ricola3D
  • 2,402
  • 17
  • 16
  • Something similar has been asked here (http://stackoverflow.com/questions/2197487/reading-a-documents-content-from-the-gdata-api), but I don't manage to get it to work : the resulting stream is under the form : "com.google.gdata.data.docs.DocumentEntry@18ad9a051687869791310..." instead of binary I expected. – Ricola3D Jul 18 '12 at 15:07

1 Answers1

0

Finally I found the solution by myself, it seems I was just using it wrong. Here is the code if someday somebody else needs !

URL entryUrl = new URL("https://docs.google.com/feeds/default/private/full/"+mydocumentid);
DocumentEntry mydocument = client.getEntry(entryUrl, DocumentEntry.class);
if (mydocument!=null) { // if we can read the document
  MediaContent content = (MediaContent) mydocument.getContent();
  //URL exportUrl = new URL(content.getUri()); // download url
  MediaSource source = client.getMedia(content);
  InputStream inStream = null;
  OutputStream outStream = null;
  try {
    inStream = source.getInputStream();
    outStream = resp.getOutputStream();
    int c;
    while ((c = inStream.read()) != -1) {
      outStream.write(c); // copy the stream, by 1byte per 1byte is very slow !
    }
  } finally {
    if (inStream != null) {
      inStream.close();
    }
    if (outStream != null) {
      outStream.flush();
      outStream.close();
    }
  }
Ricola3D
  • 2,402
  • 17
  • 16