uploadToS3 method

Future<PixelBinImage?> uploadToS3(
  1. String url,
  2. Map<String, String> fields,
  3. File file
)

Implementation

Future<PixelBinImage?> uploadToS3(
    String url, Map<String, String> fields, File file) async {
  var uri = Uri.parse(url);
  var request = http.MultipartRequest('POST', uri);

  fields.forEach((key, value) {
    request.fields[key] = value;
  });

  var stream = http.ByteStream(file.openRead());
  var length = await file.length();
  var multipartFile = http.MultipartFile('file', stream, length,
      filename: path.basename(file.path));
  request.files.add(multipartFile);

  var response = await request.send();
  if (response.statusCode != 200) {
    throw Exception('Failed to upload to S3');
  }
  return null;
}