C# .NET is in development for v1. Interested in contributing or chatting with us?Get in touch!
.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();