getFilePreview method

Future<Uint8List> getFilePreview({
  1. required String bucketId,
  2. required String fileId,
  3. int? width,
  4. int? height,
  5. String? gravity,
  6. int? quality,
  7. int? borderWidth,
  8. String? borderColor,
  9. int? borderRadius,
  10. double? opacity,
  11. int? rotation,
  12. String? background,
  13. String? output,
})

Get File Preview

Get a file preview image. Currently, this method supports preview for image files (jpg, png, and gif), other supported formats, like pdf, docs, slides, and spreadsheets, will return the file icon image. You can also pass query string arguments for cutting and resizing your preview image. Preview is supported only for image files smaller than 10MB.

Implementation

Future<Uint8List> getFilePreview(
    {required String bucketId,
    required String fileId,
    int? width,
    int? height,
    String? gravity,
    int? quality,
    int? borderWidth,
    String? borderColor,
    int? borderRadius,
    double? opacity,
    int? rotation,
    String? background,
    String? output}) async {
  final String path = '/storage/buckets/{bucketId}/files/{fileId}/preview'
      .replaceAll('{bucketId}', bucketId)
      .replaceAll('{fileId}', fileId);

  final Map<String, dynamic> params = {
    'width': width,
    'height': height,
    'gravity': gravity,
    'quality': quality,
    'borderWidth': borderWidth,
    'borderColor': borderColor,
    'borderRadius': borderRadius,
    'opacity': opacity,
    'rotation': rotation,
    'background': background,
    'output': output,
    'project': client.config['project'],
  };

  final res = await client.call(HttpMethod.get,
      path: path, params: params, responseType: ResponseType.bytes);
  return res.data;
}