I am trying to integrate uploading arbitrary files into Google Docs into an existing application. This was used to work before using renewable downloads, became mandatory. I am using Java client libraries.
The application downloads in 2 stages: - get the file resourceId file - download data
To get resourceId, I upload a 0-dimensional file (i.e. Content-Length = 0). I am handing over? Convert = false in the revolving URL (i.e. https://docs.google.com/feeds/upload/create-session/default/private/full?convert=false ).
I pass "application / octet-stream" as the content type. It seems to work, although I have different resources. Identifiers are "file: ..." files for things like images, but "pdf: ..." resourceIds for PDF files.
The second step creates a URL based on the previously obtained resource and performs a search (getEntry). The URL is in the form https://docs.google.com/feeds/default/private/full/file%3A .....
After the record is found, ResumableGDataFileUploader is used to update the contents (0-byte file) with the actual data from the downloaded file. This operation failed with a 401 Unauthorized response while creating an instance of ResumableGDataFileUploader.
Have I tried with? convert = false as well? new-revision = true and both at the same time. The result is the same.
Corresponding code snippet:
MediaFileSource mediaFile = new MediaFileSource( tempFile, "application/octet-stream"); final ResumableGDataFileUploader.Builder builder = new ResumableGDataFileUploader.Builder(client, mediaFile, documentListEntry); builder.executor(MoreExecutors.sameThreadExecutor()); builder.requestType(ResumableGDataFileUploader.RequestType.UPDATE); // This is where it fails final ResumableGDataFileUploader resumableGDataFileUploader = builder.build(); resumableGDataFileUploader.start(); return tempFile.length();
A βclientβ is an instance of DocsService configured to use OAuth. It is used to search for "documentListEntry" immediately before a given piece of code.
I had to explicitly specify the type of request, since it seems that the client library code contains an error that throws a NullPointerException for the case "update an existing record".
I have a suspicion that the problem is specifically in the sequence of actions (upload a 0-byte file to get the resourceId and then update using the actual file), but I can not understand why it does not work.
Please, help?