createSignedUrls method

Future<List<SignedUrl>> createSignedUrls(
  1. List<String> paths,
  2. int expiresIn
)

Create signed URLs to download files without requiring permissions. These URLs can be valid for a set number of seconds.

paths is the file paths to be downloaded, including the current file names. For example: createdSignedUrl(['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.

A list of SignedUrls is returned.

Implementation

Future<List<SignedUrl>> createSignedUrls(
  List<String> paths,
  int expiresIn,
) async {
  final options = FetchOptions(headers: headers);
  final response = await _storageFetch.post(
    '$url/object/sign/$bucketId',
    {
      'expiresIn': expiresIn,
      'paths': paths,
    },
    options: options,
  );
  final List<SignedUrl> urls = (response as List).map((e) {
    return SignedUrl(
      // Prevents exceptions being thrown when null value is returned
      // https://github.com/supabase/storage-api/issues/353
      path: e['path'] ?? '',
      signedUrl: '$url${e['signedURL']}',
    );
  }).toList();
  return urls;
}