Python - bucket.file.download_url()

Create a signed url for read access to a file.

from nitric.resources import bucket
from nitric.application import Nitric

assets = 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 bucket
from nitric.application import Nitric

assets = 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, bucket
from nitric.application import Nitric
from nitric.context import HttpContext

main_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 = 303
  ctx.res.headers['Location'] = [url]

Nitric.run()