|
@@ -1,5 +1,6 @@
|
|
|
package ua.be.wee.service;
|
|
|
|
|
|
+import java.io.FileInputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.net.MalformedURLException;
|
|
|
import java.nio.file.FileAlreadyExistsException;
|
|
@@ -12,6 +13,8 @@ import javax.servlet.http.Part;
|
|
|
|
|
|
import org.apache.http.HttpResponse;
|
|
|
import org.apache.http.client.methods.HttpPut;
|
|
|
+import org.apache.http.entity.FileEntity;
|
|
|
+import org.apache.http.entity.InputStreamEntity;
|
|
|
import org.apache.http.entity.StringEntity;
|
|
|
import org.apache.http.impl.client.BasicResponseHandler;
|
|
|
import org.apache.http.impl.client.CloseableHttpClient;
|
|
@@ -68,15 +71,22 @@ public class FileStorageServiceImpl implements FileStorageService {
|
|
|
}
|
|
|
|
|
|
CloseableHttpClient httpclient = HttpClients.createDefault();
|
|
|
-
|
|
|
+
|
|
|
HttpPut httpPut = new HttpPut(url);
|
|
|
|
|
|
+
|
|
|
// specify the PUT body to send to the server as part of the request
|
|
|
- httpPut.setEntity(new StringEntity(file.getInputStream().toString()));
|
|
|
+ //httpPut.setEntity(new StringEntity(file.getInputStream().toString()));
|
|
|
|
|
|
+ httpPut.setEntity(new InputStreamEntity(file.getInputStream()));
|
|
|
+
|
|
|
+
|
|
|
HttpResponse response = httpclient.execute(httpPut);
|
|
|
|
|
|
- String responseBody = new BasicResponseHandler().handleResponse(response);
|
|
|
+ String responseBody = new BasicResponseHandler().handleResponse(response);
|
|
|
+
|
|
|
+
|
|
|
+ httpclient.close();
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
if (e instanceof FileAlreadyExistsException) {
|