Я пытаюсь отправить файл через HTTP-запрос из моего экземпляра EC2.Я могу отправить файл с моего локального компьютера, но не с моего экземпляра EC2.
CloseableHttpClient client = HttpClientBuilder.create().build();
InputStream is=S3Utility.getS3Object(s3Bucket, filename, null);
HttpPost postRequest = new HttpPost(url);
for (String key : requestHeader.keySet()) {
postRequest.addHeader(key, requestHeader.get(key));
}
MultipartEntityBuilder multipartEntity = MultipartEntityBuilder.create();
multipartEntity.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
multipartEntity.addBinaryBody("file",IOUtils.toByteArray(is) , ContentType.DEFAULT_BINARY, filename);
for (String key : postData.keySet()) {
multipartEntity.addTextBody(key, postData.get(key));
}
postRequest.setEntity(multipartEntity.build());
response = client.execute(postRequest);
logger.debug("file sent.");
ответ сервера:
LOCAL
Заголовок:
{"x-forwarded-proto":"https","host":"postman-echo.com","content-length":"11084","accept-encoding":"gzip,deflate","authorization":"Bearer XYZ","cache-control":"no-cache","content-type":"multipart/form-data; boundary=z_Z49xCCKRMyAXBYOmWtxaPGt28Awf4QbLq","user-agent":"Apache-HttpClient/4.5.2 (Java/1.8.0_181)","x-forwarded-port":"443"}
файл:
eaa256da-65b0-4d03-a678-f628ec6fc838.jpeg":"data:application/octet-stream;base64,/9j/4f//RXhpZgAASUkqAAgAAAAMAAABBAABAAAAAAgAAAEBBAABAAAAgAQAABIBAwABAAAABgAAABMCAwABAAAAAQAAABoBBQABAAAAngAAABsBBQABAAAApgAAACgBAwABAAAAAgAAAA8BAgAIAAAArgAAABABAgAJAAAAtgAAADEBAgAOAAAAvwAAADIBAgAUAAAAzQAAAGmHBAABAAAA4QAAAE0DAABIAAAAAQAAAEgAAAABAAAAc2Ftc3VuZwBTTS1HOTczRgBHOTczRlhYVTNBU0c4ADIwMTk6MDg6MDMgMTg6NTM6NDMAJACaggUAAQAAAJcCAACdggUAAQAAAJ8CAAAiiAMAAQAAAAIAAAAniAMAAQAAAEABAAAAkAcABAAAADAyMjADkAIAFAAAAKcCAAAEkAIAFAAAALsCAAABkgoAAQAAAM8CAAACkgUAAQAAANcCAAADkgoAAQAAAN8CAAAEkgoAAQAAAOcCAAAFkgUAAQAAAO8CAAAHkgMAAQAAAAMAAAAJkgMAAQAAAAAAAAAAoAcABAAAADAxMDABkQcABAAAAAECAwAKkgUAAQAAAPcCAACQkgIABQAAAP8CAACRkgIABQAAAAQDAACSkgIABQAAAAkDAACGkgcADQAAAA4DAAABoAMAAQAAAAEAAAACoAQAAQAAAAAIAAADoAQAAQAAAIAEAAABowcABAAAAAEAAAABpAMAAQAAAAAAAAACpAMAAQAAAAAAAAADpAMAAQAAAAAAAAAEpAUAAQAAABsDAAAFpAMAAQAAABoAAAAGpAMAAQAAAAAAAAAIpAMAAQAAAAAAAAAJpAMAAQAAAAAAAAAKpAMAAQAAAAAAAAAgpAIADAAAACMDAAAFoAQAAQAAAC8DAAAAAAAAAQAAAGQAAACWAAAAZAAAADIwMTk6MDg6MDMgMTg6NTM6NDMAMjAxOTowODowMyAxODo1Mzo0MwCYAgAAZAAAAHQAAABkAAAAgQAAAGQAAAAAAAAACgAAAHQAAABkAAAAsAEAAGQAAAAwMzk2ADAzOTYAMDM5NgAAAAAAAAAAAAAAAAAAAAAAAAAAAABMMTJYTExEMDFWTQACAAEAAgAEAAAAUjk4AAIABwAEAAAAMDEwMAAAAAAGAAABBAABAAAAAAIAAAEBBAABAAAAgAEAAAMBAwABAAAABgAAABIBAwABAAAABgAAAAECBAABAAAAmwMAAAICBAABAAAAZaAAAAAAAAD
Статус: HTTP 200 ok
EC2
Заголовок:
{"x-forwarded-proto":"https","host":"postman-echo.com","content-length":"11077","accept-encoding":"gzip,deflate","authorization":"Bearer XYZ","cache-control":"no-cache","content-type":"multipart/form-data; boundary=npz5gJz7G58UEL_5kVxptS8Fg1TBduhNX","user-agent":"Apache-HttpClient/4.5.2 (Java/1.8.0_202)","x-forwarded-port":"443"}
Файл:
eaa256da-65b0-4d03-a678-f628ec6fc838.jpeg":"data:application/octet-stream;base64,77+977+977+977+9ABBKRklGAAEBAAABAAEAAO+/ve+/vQDvv70ACQYHExMSFRISEhUVFRYVFRUVFRUVFRUXFxYWFRYWFRUVFhgdKCAYGiUdFRUhMSElKSsuLi4XHzM4My03KC0uKwEKCgoODQ4aEBAbLR0dHS0tLS0tLSstLS0tKy0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLSstLS0t77+977+9ABEIAO+/vQEDAwEiAAIRAQMRAe+/ve+/vQAbAAACAwEBAQAAAAAAAAAAAAACAwABBAUGB++/ve+/vQA+EAABAwIEAwYEBAQFBAMAAAABAAIRAyEEEjFBBVFhEyJx77+977+977+9Mu+/ve+/ve+/vRRC77+977+9BhUjUjNi77+977+977+9U3Lvv73vv700Q++/ve+77+977+977+977+9ABBKRklGAAEBAAABAAEAAO+/ve+/vQDvv70ACQYHExMSFRISEhUVFRYVFRUVFRUVFRUXFxYWFRYWFRUVFhgdKCAYGiUdFRUhMSElKSsuLi4XHzM4My03KC0uKwEKCgoODQ4aEBAbLR0dHS0tLS0tLSstLS0tKy0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLSstLS0t77+977+9ABEIAO+/vQEDAwEiAAIRAQMRAe+/ve+/vQAbAAACAwEBAQAAAAAAAAAAAAACAwABBAUGB++/ve+/vQA+EAABAwIEAwYEBAQFBAMAAAABAAIRAyEEEjFBBVFhEyJx77+977+977+9Mu+/ve+/ve+/vRRC77+977+9BhUjUjNi77+977+977+9U3Lvv73vv700Q++/ve+
Статус: HTTP 500
Похоже, что экземпляр EC2 отправляет поврежденный поток на сервер.Может ли кто-нибудь помочь мне решить эту проблему?