As the Google Drive API document said about downloading a file:
https://www.googleapis.com/drive/v3/files/FILEID?alt=media%26key=API_KEY
If we paste this link to Chrome or Safari It will start downloading.
But the problem is
The name is changed to FIELDID
The extension is gone
For example
I have file mywork.fbx I upload to google drive, and the FileID is ABCDEFG
Then I go to the link below.
https://www.googleapis.com/drive/v3/files/ABCDEFG?alt=media%26key=MYAPIKEY
I got the file that name is ABCDEFG without extension
It should be mywork.fbx or anyname.fbx not just ABCDEFG
Tried
add &download="mywork.fbx"
use PHP header('Content-Disposition: attachment; filename="mywork.fbx"'); filename is mywork.fbx but the bandwidth is also mine too It's not only Google Drive!!!
$file_url = 'https://www.googleapis.com/drive/v3/files/ABCDEFG?alt=media&key=KEY';
header('Content-Disposition: attachment; filename="mywork.fbx"');
readfile($file_url);
check articles in stack overflow but I can't found the right one
You want to download a file which is not Google Docs using the browser.
You want to download a file with the filename which has the filename and extension of the original file.
You are using the API key.
In this case, the file is publicly shared.
If my understanding is correct, how about this answer? In this answer, webContentLink is used as the endpoint. The official document says as follows.
webContentLink:
A link for downloading the content of the file in a browser using cookie based authentication. In cases where the content is shared publicly, the content can be downloaded without any credentials.
Modified endpoint:
Please try to access the following endpoint with your browser.
https://drive.google.com/uc?export=download&id={fileId}
When you use this, please set the file ID. In this case, the file is not Google Docs.
When it accesses to the above endpoint, the file with the filename can be retrieved.
Reference:
Files of Drive API
If I misunderstood your question and this was not the direction, I apologize.
Look at the originalFilename property of https://developers.google.com/drive/api/v3/reference/files. You can use that in a content disposition header, see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition
Related
I use the Windows Azure Blob Storage to keep files there.
To download files i create urls with Shared Access Signature.
It works fine, but there is one problem.
Some files (blobs) have the header "Content-Type" set during upload and other no.
if a file has no Content-Type than on request to Azure the response will have the header Content-Type: application/octet-stream . This is exactly what i need, because in such case a browser will show "Download dialog" for a user.
But for files where this header was set on upload, it is returned and sometimes it makes a problem. For example, Content-Type: images/jpeg makes a browser to show this image, but not download it (does not show Download dialog)
So, my question is
is there a way on download with presigned url from WIndows Azure to force to use some specific response header?
I want it behave like there is no Content-Type saved for a file, even if it is saved
So, after some time browsing i finally found the documentation about it.
There are references.
https://nxt.engineering/en/blog/sas_token/
https://learn.microsoft.com/en-us/rest/api/storageservices/service-sas-examples
https://learn.microsoft.com/en-us/rest/api/storageservices/create-service-sas
For me it was needed to up the version of the API (i used the 2012 API version).
Also one useful note. It is very sensetive to a date format. The expiraton time must be in the format like "2021-11-16T04:25:00Z" .
I have added 2 new arguments
'rscd=file;%20attachment&rsct=binary&'.
and both of the must be in the signature string to sign on their correct places
So, my question is is there a way on download with presigned url from
WIndows Azure to force to use some specific response header? I want it
behave like there is no Content-Type saved for a file, even if it is
saved
Yes, you can override Content-Disposition response header in your SAS Token and the blob will be always downloaded regardless of it’s content type.
You can override this header to a value like attachment; filename=yourdesiredfilename and the blob will always be downloaded with yourdesiredfilename name.
My question is similar to What is format of Google Drive's FileID ? I need to find out whether new File has been uploaded to my drive or not using API's but I want to know the format of a folder ID in Google Drive, the one that appears in the URL bar when you open a folder in your Google drive, the thing after https://drive.google.com/drive/u/0/folders/<this part>.
Google Drive folder id doesn't have a specific guaranteed format. This (apparent format which really isn't a format) has changed in the past and may change again.
Trying to create any kind of local verification of this will be futile.
The best option would be to do a Files: get and test if you get a response. This will work better as it will also verify that the user has access to the file as well as testing that its a valid file id format.
Any (regex) attempt to verify the file id wouldn't really verify it as its not going to test if the user has access.
A folder ID starts with a 1 followed by 32 base-64 encoded digits, except unlike base64 the + is replaced by - and / is replaced by _. You can use the following regex:
/^1[A-Za-z0-9-_]{32}$/
I have successfully uploaded and downloaded files and downloaded files metadata
from OneDrive and Dropbox using Xamarin.Auth 1.5. I have done all of this for Google Drive except when
I upload a file I cannot name the file (shows as Untitled) and I cannot update
the file once it is uploaded.
Below is code for uploading a file (creating) initially:
Data for the file is in stream. Scope is https://www.googleapis.com/auth/drive.
URI uri = new Uri("https://www.googleapis.com/upload/drive/v3/files?uploadType=media");
OAuth2Request requestUpload = new OAuth2Request("POST", uri, null, (Account)authAccount);
requestUpload.AddMultipartData("body", stream, "application/json", dataFileName);
var responseUpload = await requestUpload.GetResponseAsync();
To update the file, I have tried adding the fileid to the url after files (e.g. files/fileid) and
I received System.Net.HttpStatusCode.NotFound and I know that the fileid is correct because I was
able to download the file using the same fileid. With the fileid, I also tried to use method PATCH
but I received a Xamarin.Auth error.
To rename the file, I have tried using two AddMultipartData, one for data and the other for
metadata (name) with correct formatting and all of the AddMultipartData metadata is added
inside the file with the body data. I tried adding both data and metadata in one AddMultipartData
with the same result as using two.
For both rename and update, I have tried all types of combinations, e.g. different uploadTypes, without
/upload, method PUT, IDictionary parameters, just to name a few.
Does anyone know how to do this? Thanks for any help or suggestions.
Xamarin.Auth has little to do with google drive APIs. It merely gets token for you.
All I can think of is that Xamarin.Auth intercepted some exception during PATCh and re-throw as Xamarin.Auth exception.
I suggest - issue on github. And ping me in community slack.
The Google Drive API v2 to v3 migration guide says:
The exportLinks field has been removed from files. To export Google Documents, use the files.export method instead.
I don't want to export (download) the file right away. "files.export" will actually download the file. I want a link to download the file, later. This was possible in v2 by means of the exportLinks.
How can I in v3 accomplish the same? If it is not possible, why was this useful feature removed?
Besides, (similar problem to above) downloadUrl was also removed, and the suggested alternative ("files.get with ?alt=media") downloads the file instead of providing a download link. This means there is no way in v3 to get a public short lived URL for a file?
EDIT:
there is no way in v3 to get a public short lived URL for a file?
For regular files, apparently yes.
This seems to work fine (a public short lived link to the file with its right name and contents):
https://www.googleapis.com/drive/v3/files/ID?alt=media&access_token=TOKEN
For google apps files, no (not even private, as v2 exportLinks used to be).
https://www.googleapis.com/drive/v3/files/ID/exportmimeType=TYPEv&access_token=TOKEN
Similar to regular files, this URL is a short lived link to the file contents, but lacking of its right name.
BTW, I see the API is not behaving consistently: /drive/v3/files/FILEID delivers the right file name, but /drive/v3/files/FILEID/export does not.
I think the API itself should be setting the right Content-Disposition, as it is apparently doing when issuing a /drive/v3/files/FILEID call.
This file naming problem invalidates the workaround to the lack of ExportLinks in v3.
The v2 ExportLinks allowed me to link a file (which is not the same as getting its content right away). Anyone logged in and with the proper permissions was able to access it, and the link didn't needed any access_token, and it wasn't short lived. It was good and useful.
Building a link with a raw API call like /drive/v3/files/FILEID/export (with mandatory access_token) would be an close enough workaround (it is temporary and public, not the same as it was, anyway). However, the naming problem invalidates it.
In v2, regular files have a WebContentLink and google apps files have exportLinks. In v3 exportLinks are gone, and I don't see any suitable alternative to them.
Once you query for your file by id you can use the function getWebContentLink() to get the download link of the file (eg. $file->getWebContentLink() ).
I think you're placing too much emphasis on the word "method".
There is still a link to export a file, it's https://www.googleapis.com/drive/v3/files/fileIdxxxxx/export&mimeType=xxxxx/xxxxx. Make sure you URL encode the mime type.
Eg
https://www.googleapis.com/drive/v3/files/1fGBQ81haNU_nEiC5GITZD3bxT0ppL2LHg-C0ubD4Q_s/export?mimeType=text/csv&access_token=ya29.Gmo0BMvO-pVEPKsiD9j4D-NZVGE91MChRvwOcBSg3cTHt5uAClf-jFxcovQScbO2QQhwHS95eSGW1eQQcK5G1UQ6oI4BFEJJkntEBkgriZ14GbHuvpDL7LT2pKA--WiPuNoDDIuZMm5lWtlr
These links form part of the API, so the expectation is that you've written a client that sends authenticated requests, and deals with the response data. This explains why, if you simply paste the link into a browser without an access_token, it will fail. It also explains why the filename is export, ie. it isn't intended that your client would ever use a filename, but rather it should receive the data as a stream. This SO answer discusses the situation in more detail How to set name of file downloaded from browser?
So I'm pretty new at all this. I am trying to reverse engineer a web application.
When I submit a form, it sends a POST with a request payload that looks something similar to this:
encoding=UTF8&zip=1&size=136240&html=DwQgIg_a_whole_lot_more_gibberish_not_worth_posting
Anyways, from inspecting the captured traffic from Chrome developer tools, I noticed it is encoded and sent as a zipped up html?
How would I go about reversing this to see what the content is actually being sent to the server?
What you want to do is this:
1) Get the name of the zip file
2) Get the path of the zip file (likely the root directory or the current path the form is at)
3) Generate the URL (http://site_name.com/path/to/folder/zip_file.zip)
4) Download it using a too such as wget (typing the URL into the browser may work too)
I used this technique to download all the files that get downloaded to the OTA updates on iOS devices (used burp suit to intercept the zip file name where the server was on my computer which my iDevice was connected to).
Please note: the name of the zip file you have given does not end in .zip. this may mean it doesn't have a extension; you may have to add .zip to the file manually; or it may have another ending such as .tar, .tar.gz etc.