简体   繁体   中英

How do I get the url of uploaded file?

I have uploaded an mp4 file as follows:

    import firebase_admin
    from firebase_admin import credentials
    from firebase_admin import storage
    cred = credentials.Certificate('my-app-service.json')
    firebase_admin.initialize_app(cred, {
        'storageBucket': 'amy-app-name.appspot.com'
    })

    bucket = storage.bucket()
    blob = bucket.blob('teamfk.mp4')
    blob.upload_from_filename('path/to/teamfk.mp4')

Now I can't find the syntax to get a reference to the uploaded url ?

  • To add, I should be able to view/download from browser.
  • It need not be authenticated, public is fine.

As per Google Docs - Cloud Storage

The public URL of the file can be retrieved with

blob.make_public()
blob.public_url

Here is another way! If you want to generate a URL that only valid for a specific time range you can accomplish it using that way.

file_url = blob.generate_signed_url(datetime.timedelta(days=1), method='GET') #this URL only valid for 1 day

For more details refer this link :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM