【问题标题】:S3 bucket connection failed (HTTP/1.1 504 GATEWAY_TIMEOUT)S3 存储桶连接失败 (HTTP/1.1 504 GATEWAY_TIMEOUT)
【发布时间】:2016-03-15 09:18:23
【问题描述】:

当我尝试通过命令行aws s3 cp /Users/shravan40/Downloads/scan1.jpg s3://s3_bucket_name/access_key_id 将图像上传文件上传到我的 s3 存储桶时,它会成功上传。但是当我尝试通过 Scala API 上传图像时,它显示网关超时。我已将超时时间设置为 2 分钟。

public void connect(){
    conn = new AmazonS3Client(credentials);        
}


public AmazonS3Client(AWSCredentials awsCredentials) {
    this(awsCredentials, new ClientConfiguration());
} 

public void setBucket(String bucketName){
    this.bucketName = bucketName;
    this.baseUrl = "https://s3.us-west-2.amazonaws.com/"+bucketName;
}

这里是 API 代码,

post("/api/:version/user/:id/image/upload") {
  CGMetrics.apiProfiler.profile("api.uploadImage") {
    val memberId: Long = params("id").toLong
    if (!AccountService.validateMemberId(memberId))
      APIResponseError(APIResponseCode.NOT_FOUND, "Invalid Member Id")
    else {
      val filePath: String = getUploadedFilePath("file_path", "file")
      val fileName: String = getParam("filename").get.toString

      if (filePath != null) {
        val (uploadImageUrl, resizedImageHeight, resizedImageWidth) = MediaService.uploadImage(memberId, 0, fileName, filePath)
        APIResponseOK(Map("imgUrl" -> uploadImageUrl, "imgHeight" -> resizedImageHeight, "imgWidth" -> resizedImageWidth))
      } else {
        APIResponseError(APIResponseCode.UNPROCESSABLE_ENTITY, "No File Found")
      }
    }
  } 
}

还有getUploadFilePath方法,

private def getUploadedFilePath(filePathKey: String = "file_path", fieldName: String = "file")(implicit request: HttpServletRequest): String = {

val filePath: String = getParam(filePathKey) match {
  case Some(x) => x
  case None => fileParams.get(fieldName) match {
    case Some(file) =>

      val fileName = file.getName
      val ext = Helper.getFileExtension("/tmp/" + fileName)

      Log.logger(Log.FILE.DEFAULT).debug("file name = " + fileName)
      Log.logger(Log.FILE.DEFAULT).debug("file ext = " + ext)

      val tempFile = File.createTempFile(fileName, "." + ext)
      Helper.writeToFile(tempFile, file.get())
      Log.logger(Log.FILE.DEFAULT).info("Created Temporary Asset : " + fileName + " at  " + tempFile.getAbsolutePath)

      tempFile.getAbsolutePath
    case None =>
      null
  }
}

filePath
}

更新:现在文件正在上传到 S3 存储桶,但没有确认。

有什么建议吗?

【问题讨论】:

  • 访问存储桶不是通过 http 协议完成的,而是通过 s3 协议完成的,例如。您的存储桶 url 应该类似于 s3://s3.us-west-2.amazonaws.com/bucketName。如果您想通过 http 访问它,您可以在您的存储桶上启用静态 Web 托管。
  • @MartinHansen :我尝试使用 s3://s3.us-west-2.amazonaws.com/bucketName ,但响应保持不变。
  • 只需使用s3://bucketName(这就是我所做的) - 我只是复制粘贴您的解决方案并将 http:// 与 s3:// 协议交换为示例。我不知道您存储桶的完整 uri :)

标签: java scala amazon-web-services amazon-s3


【解决方案1】:

我的方法 uplodImage 存在一些问题,无法创建缩略图,这就是我超时的原因。

我在端口 4381 上运行 reddis 服务器,但提供了默认端口号,即 6397

【讨论】:

    猜你喜欢
    • 2018-02-26
    • 2016-11-17
    • 2017-10-19
    • 2016-03-31
    • 2019-01-18
    • 2020-02-26
    • 2023-01-18
    • 2019-11-25
    • 2019-07-11
    相关资源
    最近更新 更多