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 downloadingfinal downloadUrl = await logo.getDownloadUrl();
Parameters
- Name
expiry
- Optional
- Optional
- Type
- int
- Description
Seconds until link expiry. Defaults to
600
, Maximum of604800
(7 days).
Examples
Create a readable link that is valid for the next 5 minutes
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 downloadingfinal 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 Dec 19, 2024