将图像抖动加载到S3存储桶

时间:2018-08-28 00:17:09

标签: amazon-web-services amazon-s3 dart flutter

我想使用AWS预签名密钥将图像上传到S3存储桶。此curl命令有效:

curl -X PUT-上传文件file.txt“签名密钥(URL)”

如何用飞镖/扑打来完成这项工作?

1 个答案:

答案 0 :(得分:0)

如果使用“多部分表单”帖子,则HTTP请求的http边界部分将存储在S3中文件的第一字节中。不要。

此功能有效:

  Future<void> uploadImage(File imageFile, String url, String imagetype) async {
    final length = await imageFile.length();
    final path = imageFile.path;
    print('Uploading image length: $length path:$path to url:$url');
    try {
      var response = await http.put(url, body: imageFile.readAsBytesSync(), headers: {"Content-Type": "image/" + imagetype});
      print("Uploading image status code: ${response.statusCode}");
      print("Uploading image result: ${response.body}");
      return;
    } catch (error) {
      print('Error uploading:' + error.toString());
      throw error;
    }
  }