Python - bucket.file.download_url()
Create a signed url for read access to a file.
from nitric.resources import bucketfrom nitric.application import Nitricassets = bucket('assets').allow('read')logo = assets.file('images/logo.png')download_url = await logo.download_url()Nitric.run()
Earlier versions of the Nitric SDK used 'reading'. The latest version uses 'read'.
Parameters
- Name
expiry
- Optional
- Optional
- Type
- number
- Description
Seconds until link expiry. Maximum of 604800 (7 days).
Examples
Create a readable link that is valid for the next 5 minutes
from nitric.resources import bucketfrom nitric.application import Nitricassets = bucket('assets').allow('read')logo = assets.file('images/logo.png')logo_url = await logo.download_url(expiry=300)Nitric.run()
Get an image url for rendering
from nitric.resources import api, bucketfrom nitric.application import Nitricfrom nitric.context import HttpContextmain_api = api('main')images = bucket('images').allow('read')@main_api.get('/images/:id')async def get_image(ctx: HttpContext):id = ctx.req.params['id']url = await images.file(id).download_url()ctx.res.status = 303ctx.res.headers['Location'] = [url]Nitric.run()
Last updated on Dec 19, 2024