amazon-web-services - Flutter 将图像加载到 S3 存储桶

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

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

curl -X PUT --upload-file file.txt "签名 key (URL)"

如何使用 dart/flutter 完成此操作?

最佳答案

如果您使用多部分表单发布,则 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;
    }
  }  

关于amazon-web-services - Flutter 将图像加载到 S3 存储桶,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52048468/

相关文章:

java - 在 Java 中的 SOAP over HTTP Web 服务中调用 Amazon S3 客户端时失败

ios - Flutter 地理定位器插件 Geolocator().getCurrentPosition 不返回准确的 lng 和 lat 坐标

user-interface - StreamBuilder 仅在 Flutter 中的流结束时更新

amazon-web-services - 如何找出 AWS 上每个实例每月的成本

amazon-web-services - 我想知道如何通过修改此 lambda 代码将数据导入应用程序

php - AWS S3 PHP 进度条(服务器到云)

flutter - 如何解决'注册对象时未在GetIt内部注册类型为xxx的对象未注册?

amazon-web-services - gradle构建文件在构建期间显示错误

amazon-web-services - 如何从 kubernetes pod 中识别主机云提供商?

amazon-web-services - AWS Cloudformation 和自动扩展 : The requested configuration is currently not supported. 启动 EC2 实例失败