Status Update
Comments
ja...@google.com <ja...@google.com> #2
Hello,
Thanks for your report. As you can see in the
The alt=media URL parameter tells the server that a download of content is being requested.
But since Apps Script runs on a server-side, it's not possible to use it to download files into your local storage. Therefore the response is 200
"correct" but the parameter alt
is not valid in this context. If you remove this parameter it you will get the
Cheers!
aj...@gmail.com <aj...@gmail.com> #3
Gets a file's metadata or content by ID.
The documentation states, that the Drive.Files.get() method can get the content of the file. But there is no explanation in the documentation about how to use Drive.Files.get() to get the content of the file. Please let me know if there is a way to use Drive.Files.get() to get the content of the file directly. And that statement in the documentation clearly distinguishes between metadata and content. Metadata is not content. They are two different things. I don't want the metadata. I want the file content.
This is not a feature request. The documentation clearly states that the Drive.Files.get() method gets either metadata OR CONTENT. If the documentation states that it can get the file content, then it should be able to get the file content, or it's a bug.
So, please respond and explain how to get the CONTENT of the file with Drive.Files.get() because the documentation states that it's possible. I'm not asking for an explanation of how to download to a drive. And if the documentations states that the content can be gotten, but it can't, then is it a bug, or is the documentation wrong?
ja...@google.com <ja...@google.com> #4
This is not a documentation or API bug. As we can read in the Drive API
Content: The binary or text body of the file. Some content examples you can store in Google Drive are images, videos, text, and PDF.
You can get the binary content by using the webContentLink
parameter, or use the text/plain
. If you have any other question regarding the use of the API, please head over Stackoverflow.com using the tag [google-drive-api].
Cheers!
aj...@gmail.com <aj...@gmail.com> #5
I guess this would be a feature request for the Google Apps Script Advanced Drive API.
pa...@gmail.com <pa...@gmail.com> #6
As far as the workarounds offered, export only works on Docs files. I'm just trying to get the content of a text file. And as stated in the SO post from the last comment, the webContentLink can only used for downloading content stored as binary files.
Lastly, the reason I have to use the Advanced Drive Service is because my apps script is running in a Shared Drive and the standard DriveApp does not function when run the apps script is run in a Shared Drive.
I would really appreciate some help with this.
sh...@gmail.com <sh...@gmail.com> #7
I still believe this is a bug, but not a bug of Google Drive API, but of Google Apps Script.
The problem is: As the issue description on the top of this thread reports,
Drive.Files.get(fileId,{alt:"media"}) should return the binary content of the file as the documentation
Drive.Files.get(fileId,{alt:"media"}) sure returns response code 200, so there's nothing wrong on Drive API, but somehow Google Apps Script cannot complete this method without causing an error although the expected output itself is included in the error message. So there's something that needs to be fixed on the Advanced Drive Service in Google Apps Script.
(Maybe because Apps Script is probably expecting a JSON format response from files.get() although it isn't that way when the content(not metadata) of the file is requested? This bug does not happen if the content of the file itself is a JSON format.)
Exception on Apps Script here:
This is a serious bug since, there would be no way on Apps Script Advanced Drive Service to access the content of the Google Drive file without using the "webContentLink" on the metadata of the file, if Drive.Files.get(fileId,{alt:"media"}) doesn't work. Accessing it using the "webContentLink" on Apps Script needs to be done using UrlFetchApp.fetch(), which requires a scope to allow external request and, thus, is a security risk.
The Drive API sure returns the correct(expected) output, but Google Apps Script Advanced Drive Service seems to be failing to interpret the output correctly.
jp...@google.com <jp...@google.com>
jp...@google.com <jp...@google.com> #8
This is most definitely a bug and still a problem with Drive v3.
Description
Can't get file content with Advanced Drive Service in Apps Script. Results in error message even though the Response Code is 200.
Drive.Files.get('File ID Here',{alt:'media'}); message: Response Code: 200. Message: File content is here
code sample
What steps will reproduce the problem?
What is the expected output? The expected output is the file content
What do you see instead?
An error message that halts the code
ERROR MESSAGE message: Response Code: 200. Message: File content is here
Additional information below. Being able to use Drive.Files.get() to get file content is critical to be able to avoid using UrlFetchApp.fetch() which requires a scope to allow external requests. External requests can be a security concern, and therefore is desirable to be avoided. The get method actually works, has a status code of 200, and gets file content, but it just doesn't return the file content without an error.