createSignedUrlsResult method
- List<
String> paths, - int expiresIn, {
- DownloadBehavior? download,
- String? cacheNonce,
Create signed URLs to download files without requiring permissions. These URLs can be valid for a set number of seconds.
Returns one SignedUrlResult per requested path. Each result is either a SignedUrlSuccess (with a ready-to-use signed URL) or a SignedUrlFailure (when the server could not sign that path, e.g. the file does not exist).
paths is the file paths to be downloaded, including the current file
names. For example: createSignedUrlsResult(['folder/image.png', 'folder2/image2.png']).
expiresIn is the number of seconds until the signed URLs expire. For
example, 60 for URLs which are valid for one minute.
download triggers the files to be downloaded rather than opened in the
browser by setting the response's Content-Disposition header. Use
DownloadBehavior.withOriginalName to keep the original file name or
DownloadBehavior.named to override it.
cacheNonce appends a cacheNonce query parameter to each URL to bypass
CDN caching for a specific file version.
Implementation
Future<List<SignedUrlResult>> createSignedUrlsResult(
List<String> paths,
int expiresIn, {
DownloadBehavior? download,
String? cacheNonce,
}) async {
final options = _fetchOptions;
final response = await _storageFetch.post(
'$url/object/sign/$bucketId',
{
'expiresIn': expiresIn,
'paths': paths,
},
options: options,
);
return (response as List).map<SignedUrlResult>((e) {
final signedUrlPath = e['signedURL'] as String?;
final path = e['path'] as String? ?? '';
if (signedUrlPath != null) {
return SignedUrlSuccess(
path: path,
signedUrl: _withUrlOptions(
'$url$signedUrlPath',
download: download,
cacheNonce: cacheNonce,
),
);
}
return SignedUrlFailure(
path: path,
error: e['error'] as String? ?? 'Unknown error',
);
}).toList();
}