You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter使用aws_s3_upload上传至AWS S3时遇Broken pipe错误求助

Flutter使用aws_s3_upload上传S3遇Broken pipe错误

在Flutter应用中使用aws_s3_upload包将文件上传至AWS S3存储桶时,持续遇到Broken pipe错误。

上传代码片段

Future<String> uploadImage_to_S3(
      File image, User? currentUser, String whichFolderToPut) async {
    // image = await _compressImage(image);
    try {
      // Create a unique filename for the image
      String fileName =
 '${currentUser?.uid}_${currentUser?.email}_${DateTime.now().millisecondsSinceEpoch.toString()}${path.extension(image.path)}';

      // AWS S3 configuration
      final awsAccessKey = "xxxxxxxxxxxx";
      final awsSecretKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
      final bucketName = "alliancenetwork-production";
      final region = "ap-south-1";

      // Upload the image to S3
      final result = await AwsS3.uploadFile(
        accessKey: awsAccessKey,
        secretKey: awsSecretKey,
        file: image,
        bucket: bucketName,
        region: region,
        key: "$whichFolderToPut/$fileName",
        metadata: {
          'Content-Type': 'image/${path.extension(image.path).substring(1)}'
        },
      );

      if (result != null) {
        // The result is the URL of the uploaded file
        return result;
      } else {
        throw Exception('Failed to upload image to S3');
      }
    } catch (e) {
      // Handle any errors that occur during the upload
      print('Failed to upload image: $e');
      return 'error: image upload to S3 failed';
    }
  }

错误信息

Failed to upload to AWS, with exception:
Broken pipe

已完成的排查步骤

  • 确认网络连接稳定
  • 验证AWS凭证及S3存储桶上传权限
  • 尝试延长请求超时时间
  • 确认文件大小合规且读取正常
  • 记录了详细错误信息

可能的解决方案建议

  • 检查文件读取完整性:上传前确保文件未被占用、未损坏,可尝试重新读取文件内容后再发起上传
  • 调整上传分块参数:若aws_s3_upload支持分块上传配置,尝试减小分块大小或降低并发数,避免因网络波动导致连接中断
  • 确认区域端点正确性:ap-south-1区域的S3端点为s3.ap-south-1.amazonaws.com,可尝试在上传时显式指定端点URL(如果包支持该参数)
  • 排查SSL连接问题:部分设备或网络环境下SSL证书验证异常会导致连接断开,可在测试环境临时禁用证书验证排查,生产环境需确保证书配置正常
  • 更换上传SDK:若aws_s3_upload包存在兼容性问题,可尝试使用AWS官方的amplify_storage_s3或直接基于http包实现签名上传逻辑

内容的提问来源于stack exchange,提问作者sahil karni

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 09:22:03