S3存储桶连接失败(HTTP / 1.1 504 GATEWAY_TIMEOUT)

时间:2016-03-15 09:18:23

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

当我尝试通过命令行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存储桶,但没有相应的确认。

有什么建议吗?

1 个答案:

答案 0 :(得分:-1)

我的方法uplodImage存在一些问题,无法获得创建缩略图,这就是为什么我要抽出时间。

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