AWS s3映像放置对象

时间:2018-10-15 09:36:38

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

我正在尝试将图像从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]

1 个答案:

答案 0 :(得分:1)

您可以尝试使用HTTPS代替HTTP。 AWS Client似乎与HTTP有关。