how to auth a request to download google drive files - python-requests

i want to download files from google drive, in especific i want to download some google docs, the problem is that i can´t use the api because the api has a limit of 10 mb to export google docs, so i was trying to use requests module, the problem is that the request isn´t auth so the content of the download is not visible because the google doc is not publicy shared, is there any way to auth my request to download the needed files?
i used
r=requests.get(url)
and then
with open(path,wb) as f:
f.write(r.content)

Related

How to get google cloud storage public url out from firebase storage download url?

In our system the users upload their images using our mobile app to firebase storage which is a wrapper over google cloud storage bucket, the mobile app is using this library to do the upload, and then use the getDownloadUrl method (described in the link) to generate a download link like the following:
https://firebasestorage.googleapis.com/v0/b/{BUCKET_NAME}/o/{PARENT_FOLDER}/{IMAGE_NAME}?alt=media&token={UUID}
Then it sends the URL to our BE to store the link.
The download time for firebase storage links is much longer than downloading the exact same image directly from google cloud storage link which is simply could be generated from the following link template
https://storage.googleapis.com/{BUCKET_NAME}/{PARENT_FOLDER}/{IMAGE_NAME}.
As GCP link is faster (according to our own benchmark), then we need a way to map firebase link into its counter part in GCP storage to improve the download performance.
The solution described above to do the mapping is right for any image that is publicly available in the GCP bucket, however, if the image is not publicly available then it could be accessed using firebase link (maybe because it has the token in the link), but we can not access it using the GCP link and it gives the following error:
<Error>
<Code>AccessDenied</Code>
<Message>Access denied.</Message>
<Details>Anonymous caller does not have storage.objects.get access to the Google Cloud Storage object.</Details>
</Error>
My question is:
How can we access the image from GCP storage link, even if it is not public, given that we can not make all images public due to security reasons?

Can I make firebase file URLs publicly available without requiring token?

I am using firebase to allow users to upload their files to the Storage buckets. I was using the getDownLoadURL() to fetch the publicly available URL...however, this comes with an embedded token to allow access to the file.
In my same app, I'm using the Google Document viewer which takes a URL to preview the doc. Unfortunately, the Google Doc Viewer does not work with the firebase URLs's with the embedded token.
In Google Console, on an individual file, I click to make it public. In that case, the URL is now reachable via the https://storage.googleapis.com// format...and I don't need to use the token which works great.
So, what I want to do is mark/make a file public when I'm uploading it to firebase. I have reviewed the firebase docs and there doesn't seem to be a makePublic() method like there is on the Google API's.
Is there a way I can mark a file as public during upload, so that it can be accessed without any token?
The other solution was that I could update the bucket to be accessible, but this makes it totally open to be browsed at https://storage.googleapis.com/, which I don't want to do.
The client-side Firebase APIs don't know anything about the underlying Google Cloud Platform configurations for public content in storage buckets. So that won't be an option.
You will have to involve some backend code to change the object's configuration after it's uploaded. You could set up your own API endpoint via Cloud Functions (or whatever backend you want) to run one of the Google Cloud Storage server SDKs to set the file as public. (You will probably also want some way to authorize that the user calling your API should be able to make this change.)

How do I get publicly accessible URL from firebase storage?

It's really simple: I'm manually uploading files to firebase storage (some pictures that I want to use in my app). I need the public http address, but all I can find there is this type of link gs://myapp.appspot.com/logo3.png. How do I get from that to a URL that I can actually use in my browser?
Cloud Storage buckets do not have publicly accessible URLs by default. You have at least two options to get one:
Write some code in your app to get a download URL for the content. I've linked to the instructions for JavaScript, since you haven't indicated the client platform you're working with.
If you're just trying to get a static URL without calling an API, you will have to use the Google Cloud console to mark the entire storage bucket as "public", then build URLs to the content as described in the documentation.

How to allow users to download from firebase storage

I have looked on the docs and couldn't find the mention of a file downloading directly to the user from my firebase storage. I saw CORS but is that what I need to use?
I want a user to click on a download symbol on a picture and be able to get it.
Thanks!
CORS is one way of handling http requests, intended to help you control cross-origin requests. That is unrelated to getting a download link for a file in Firebase Storage. What you want is documented here: https://firebase.google.com/docs/storage/web/download-files

Downloading file with service account using signed url in Google Cloud Storage

My Requirement is to generate signed Url for drive uploaded document
which will be shared with clients so that they can able to download
files form drive without any authentication.
As newbie to use drive API for first time, I am using .NET libraries to call drive API. I have setup the service account for Google API as mentioned in the document. I am able to make API call using service account and able to upload the files. I reffered to How to sign url in .net for google cloud storage to create the sign url. but after accessing the mentioned url receiving following error:
<Error> <Code>InvalidBucketName</Code> <Message>The specified bucket
is not valid.</Message> </Error>
I am not sure about GoogleBucketName and GoogleBucketDir. Can anybody tell me where i would get GoogleBucketName & GoogleBucketDir. Currently i am setting GoogleBucketName to Prject Name i created in google developer console https://console.developers.google.com/ and GoogleBucketDir as empty string. Thanks in advance.
After you upload a file you are returned a file resource.
File resource contains a field called alternatelink
alternateLink string A link for opening the file in a relevant Google
editor or viewer.
You can share this link with other users they will be able to open the file in drive they should also be able to download it from drive.
There is another field called downloadUrl which might let them download it but I haven't tested that one personal. If I remember correctly downloadUrl was null sometimes so I didn't use it.
Console.WriteLine("Alternate link: " + item.AlternateLink);
Google Drive API Link to file Tutorial

Resources