Node.js - bucket.file.getDownloadUrl()

Create a download url for a file within a bucket.

import { bucket } from '@nitric/sdk'

const assets = bucket('assets').allow('read', 'write')

const logo = assets.file('images/logo.png')

// Create a read-only signed url reference for downloading
const downloadUrl = await logo.getDownloadUrl()

Parameters

  • Name
    options
    Optional
    Optional
    Type
    SignUrlOptions
    Description

    Additional options when creating a signed URL.

    • Name
      expiry
      Optional
      Optional
      Type
      number
      Description

      Seconds until link expiry. Defaults to 600, Maximum of 604800 (7 days).

Examples

Create a readable link that is valid for the next 5 minutes

import { bucket } from '@nitric/sdk'

const assets = bucket('assets').allow('read')

const logo = assets.file('images/logo.png')

const logoUrl = await logo.getDownloadUrl({
  expiry: 300,
})

Redirect response to an image URL

import { api, bucket } from '@nitric/sdk'

const mainApi = api('main')
const images = bucket('images').allow('read')

mainApi.get('/images/:id', async ({ req, res }) => {
  const { id } = req.params
  const signedUrl = await images.file(id).getDownloadUrl()
  res.status = 303
  res.headers['Location'] = [signedUrl]
})