The C# .NET SDK currently only supports legacy versions of Nitric prior to v1. This version is maintained for compatibility with existing projects and not recommended for new projects. New projects should be started using a supported SDK (presented automatically using the `nitric new` command) orget in touch to request an update to the latest version.
.NET - Bucket.File.GetDownloadUrl()
Create a download url for a file within a bucket.
using Nitric.Sdk;
using Nitric.Sdk.Storage;
var assets = Nitric.Bucket('assets').With(BucketPermission.Reading);
var logo = assets.File('images/logo.png');
// Create a read-only signed url reference for downloading
var downloadUrl = 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
using Nitric.Sdk;
using Nitric.Sdk.Storage;
var assets = Nitric.Bucket('assets').With(BucketPermission.Reading);
var logo = assets.File('images/logo.png');
// Create a read-only signed url reference for downloading
var downloadUrl = logo.GetDownloadUrl(300);
Nitric.Run();
Redirect response to an image url
using Nitric.Sdk;
using Nitric.Sdk.Storage;
var images = Nitric.Bucket('images').With(BucketPermission.Reading);
var mainApi = Nitric.Api("main");
mainApi.Get("/images/:id", context => {
var id = context.Req.PathParams["id"];
var signedUrl = images.File(id).GetDownloadUrl();
context.Res.Status = 303;
context.Res.Headers["Location"] = new string[] { signedUrl };
return context;
});
Nitric.Run();