presign method
Future<PresignedFileUrl>
presign(
- String path, {
- PresignedFileMethod method = PresignedFileMethod.get,
- int expiresIn = 3600,
Implementation
Future<PresignedFileUrl> presign(String path, {PresignedFileMethod method = PresignedFileMethod.get, int expiresIn = 3600}) async {
_path(path);
if (expiresIn < 1 || expiresIn > 604800) throw ArgumentError.value(expiresIn, 'expiresIn', 'Expected 1–604800 seconds');
final base = await _files._endpoint();
final url = base.replace(pathSegments: [...base.pathSegments.where((part) => part.isNotEmpty), 'v1', 'presign']);
final request = http.Request('POST', url)
..headers['Content-Type'] = 'application/json'
..body = jsonEncode({'target': target.toJson(), 'path': path, 'method': method.name.toUpperCase(), 'expires_in': expiresIn});
return PresignedFileUrl.fromJson(await _files._json(request));
}