我已经能够成功上传 ~1kb 的小文件,但是当我尝试上传大于 1Mb 的较大文件时,我得到了这个异常:
java.io.IOException: Error writing to server
at sun.net.www.protocol.http.HttpURLConnection.writeRequests(HttpURLConnection.java:699)
at sun.net.www.protocol.http.HttpURLConnection.writeRequests(HttpURLConnection.java:711)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1585)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:347)
at com.red5.VimeoTechRojoIntegration.uploadFromEFSToS3(VimeoTechRojoIntegration.java:209)
at com.red5.Red5ProLive$1.run(Red5ProLive.java:128)
at java.lang.Thread.run(Thread.java:748)
要上传我正在起诉此代码
OutputStream out = null;
InputStream in = null;
HttpURLConnection connection = null;
try {
URL url = new URL(signedURLS3);
in = new FileInputStream(videoEFSPath);
System.out.println("establish connection");
connection=(HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("PUT");
connection.setRequestProperty("Content-Type", "application/octet-stream");
System.out.println("get output stream");
out = (OutputStream) connection.getOutputStream();
System.out.println("copy");
IOUtils.copyLarge(in,out);
System.out.println("copy finished");
int responseCode = connection.getResponseCode();
if (responseCode < 300)
return "";
return "{\"error\":\"The upload to S3 failed. AWS server returned response code "+responseCode+"\"}";
}
问题是什么?