use of org.apache.http.entity.mime.content.FileBody in project syncope by apache.
the class HttpUtils method postWithDigestAuth.
public String postWithDigestAuth(final String url, final String file) {
String responseBodyAsString = "";
try (CloseableHttpResponse response = httpClient.execute(targetHost, httpPost(url, MultipartEntityBuilder.create().addPart("bin", new FileBody(new File(file))).build()), setAuth(targetHost, new DigestScheme()))) {
responseBodyAsString = IOUtils.toString(response.getEntity().getContent(), Charset.forName("UTF-8"));
handler.logOutput("Http status: " + response.getStatusLine().getStatusCode(), true);
InstallLog.getInstance().info("Http status: " + response.getStatusLine().getStatusCode());
} catch (IOException e) {
final String messageError = "Error calling " + url + ": " + e.getMessage();
handler.emitError(messageError, messageError);
InstallLog.getInstance().error(messageError);
}
return responseBodyAsString;
}
use of org.apache.http.entity.mime.content.FileBody in project product-iots by wso2.
the class HTTPInvoker method uploadFile.
public static HTTPResponse uploadFile(String url, String fileName, String fileContentType) {
HttpPost post = null;
HttpResponse response = null;
HTTPResponse httpResponse = new HTTPResponse();
CloseableHttpClient httpclient = null;
try {
httpclient = (CloseableHttpClient) createHttpClient();
post = new HttpPost(url);
File file = new File(fileName);
MultipartEntity mpEntity = new MultipartEntity();
ContentBody cbFile = new FileBody(file, fileContentType);
mpEntity.addPart("file", cbFile);
post.setEntity(mpEntity);
post.setHeader(Constants.Header.AUTH, OAUTH_BEARER + oAuthToken);
// post.setHeader(Constants.Header.CONTENT_TYPE, "multipart/form-data");
post.setHeader("Accept", Constants.ContentType.APPLICATION_JSON);
response = httpclient.execute(post);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (KeyStoreException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
}
BufferedReader rd = null;
try {
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
} catch (IOException e) {
e.printStackTrace();
}
StringBuffer result = new StringBuffer();
String line = "";
try {
while ((line = rd.readLine()) != null) {
result.append(line);
}
} catch (IOException e) {
e.printStackTrace();
}
httpResponse.setResponseCode(response.getStatusLine().getStatusCode());
httpResponse.setResponse(result.toString());
try {
httpclient.close();
} catch (IOException e) {
e.printStackTrace();
}
return httpResponse;
}
use of org.apache.http.entity.mime.content.FileBody in project questdb by bluestreak01.
the class HttpServerTest method upload.
private static void upload(File file) throws IOException {
HttpPost post = new HttpPost("http://localhost:9000/upload");
try (CloseableHttpClient client = HttpClients.createDefault()) {
MultipartEntityBuilder b = MultipartEntityBuilder.create();
b.addPart("data", new FileBody(file));
post.setEntity(b.build());
client.execute(post);
}
}
use of org.apache.http.entity.mime.content.FileBody in project mobile-android by photo.
the class ApiBase method createFileOnlyMultipartEntity.
private HttpEntity createFileOnlyMultipartEntity(ApiRequest request) throws UnsupportedEncodingException {
MultipartEntity entity = new MultipartEntity();
for (Parameter<?> parameter : request.getParametersMime()) {
if (parameter.getValue() instanceof File) {
File file = (File) parameter.getValue();
entity.addPart(parameter.getName(), new FileBody(file));
}
}
return entity;
}
use of org.apache.http.entity.mime.content.FileBody in project stanbol by apache.
the class ReasonersOfflineTest method setupMultipart.
@Before
public void setupMultipart() {
FileBody bin = new FileBody(file);
multiPart = new MultipartEntity();
multiPart.addPart(fileParam, bin);
}
Aggregations