gpt4 book ai didi

java - AWS s3图像放置对象

转载 作者:行者123 更新时间:2023-12-02 10:42:41 25 4
gpt4 key购买 nike

我正在尝试将图像从 base64 解码为字节数组并加载到 S3 存储桶中。下面是我的代码,

 byte[] imagecontent = Base64.decodeBase64(IMMAGE_CONTENT);
if(imagecontent .length>0) {

input = new ByteArrayInputStream(screenshot);
String file_name = "img_SOME_LOGIC.jpg";
conn.putObject( this.bucketname, file_name, input, new ObjectMetadata());

}

上面的代码对于文本文档运行良好。意思是读取文本文件并上传。但是上面不适用于图像。
以下是我得到的错误,

com.amazonaws.AmazonClientException: Unable to unmarshall error response (The declaration for the entity "ContentType" must end with '>'.)
at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:532)
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:283)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:168)
at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:2555)
at com.amazonaws.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:1044)
at com.amazonaws.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:928)

你能帮我吗?

更新:

[Fatal Error] strict.dtd:81:5: The declaration for the entity "ContentType" must end with '>'.
97943 [Thread-62-s3store-executor[20 20]] ERROR c.a.h.AmazonHttpClient - Unable to unmarshall error response (The declaration for the entity "ContentType" must end with '>'.)
org.xml.sax.SAXParseException: The declaration for the entity "ContentType" must end with '>'.
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source) ~[xercesImpl-2.11.0.jar:?]
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source) ~[xercesImpl-2.11.0.jar:?]
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source) ~[?:1.8.0_112]
at com.amazonaws.util.XpathUtils.documentFrom(XpathUtils.java:67) ~[aws-java-sdk-1.2.15.jar:?]
at com.amazonaws.services.s3.internal.S3ErrorResponseHandler.handle(S3ErrorResponseHandler.java:63) ~[aws-java-sdk-1.2.15.jar:?]
at com.amazonaws.services.s3.internal.S3ErrorResponseHandler.handle(S3ErrorResponseHandler.java:38) ~[aws-java-sdk-1.2.15.jar:?]
at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:516) [aws-java-sdk-1.2.15.jar:?]
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:283) [aws-java-sdk-1.2.15.jar:?]
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:168) [aws-java-sdk-1.2.15.jar:?]
at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:2555) [aws-java-sdk-1.2.15.jar:?]
at com.amazonaws.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:1044) [aws-java-sdk-1.2.15.jar:?]
at com.amazonaws.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:928) [aws-java-sdk-1.2.15.jar:?]
at com.bgt.aggregation.bolt.s3bolt.execute(s3bolt.java:171) [classes/:?]
at org.apache.storm.daemon.executor$fn__5044$tuple_action_fn__5046.invoke(executor.clj:727) [storm-core-1.1.0.jar:1.1.0]
at org.apache.storm.daemon.executor$mk_task_receiver$fn__4965.invoke(executor.clj:459) [storm-core-1.1.0.jar:1.1.0]
at org.apache.storm.disruptor$clojure_handler$reify__4480.onEvent(disruptor.clj:40) [storm-core-1.1.0.jar:1.1.0]
at org.apache.storm.utils.DisruptorQueue.consumeBatchToCursor(DisruptorQueue.java:472) [storm-core-1.1.0.jar:1.1.0]
at org.apache.storm.utils.DisruptorQueue.consumeBatchWhenAvailable(DisruptorQueue.java:451) [storm-core-1.1.0.jar:1.1.0]
at org.apache.storm.disruptor$consume_batch_when_available.invoke(disruptor.clj:73) [storm-core-1.1.0.jar:1.1.0]
at org.apache.storm.daemon.executor$fn__5044$fn__5057$fn__5110.invoke(executor.clj:846) [storm-core-1.1.0.jar:1.1.0]
at org.apache.storm.util$async_loop$fn__557.invoke(util.clj:484) [storm-core-1.1.0.jar:1.1.0]
at clojure.lang.AFn.run(AFn.java:22) [clojure-1.7.0.jar:?]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_112]

最佳答案

您可以尝试使用 HTTPS 而不是 HTTP。 AWS 客户端似乎存在 HTTP 问题。

关于java - AWS s3图像放置对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52813764/

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