Dart - bucket.file.getDownloadUrl()

Create a download url for a file within a bucket.

import 'package:nitric_sdk/nitric.dart';
final assets = Nitric.bucket("assets").allow([
BucketPermission.read,
]);
final logo = assets.file("images/logo.png");
// Create a read-only url reference for downloading
final downloadUrl = await logo.getDownloadUrl();

Parameters

  • Name
    expiry
    Optional
    Optional
    Type
    int
    Description

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

Examples

import 'package:nitric_sdk/nitric.dart';
final assets = Nitric.bucket("assets").allow([
BucketPermission.read,
]);
final logo = assets.file("images/logo.png");
// Create a read-only url reference for downloading
final downloadUrl = await logo.getDownloadUrl(expiry: 300);

Redirect response to an image URL

import 'package:nitric_sdk/nitric.dart';
final mainApi = Nitric.api("main");
final images = Nitric.bucket("assets").allow([
BucketPermission.read,
]);
mainApi.get("/images/:id", (ctx) async {
final id = ctx.req.pathParams["id"]!;
final signedUrl = await images.file(id).getDownloadUrl();
ctx.res.status = 303;
ctx.res.headers["Location"] = [signedUrl];
return ctx;
});
Last updated on Oct 11, 2024