gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 09:28:35 25 4
gpt4 key购买 nike

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

有什么建议吗?

最佳答案

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

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

关于java - S3 存储桶连接失败 (HTTP/1.1 504 GATEWAY_TIMEOUT),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36007006/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com