List of usage examples for org.apache.http.entity.mime.content FileBody FileBody
public FileBody(final File file)
From source file:net.asplode.tumblr.VideoPost.java
/** * @param video Video to upload./*from w w w. jav a2 s . c o m*/ * @throws UnsupportedEncodingException */ public void setSourceFile(File video) throws UnsupportedEncodingException { entity.addPart("data", new FileBody(video)); }
From source file:poisondog.net.ApacheHttpPost.java
public HttpResponse execute(HttpParameter parameter) throws IOException { for (String key : parameter.textKeys()) { mBuilder.addTextBody(key, parameter.getText(key)); }// w ww. j a v a 2 s .co m for (String key : parameter.fileKeys()) { mBuilder.addPart(key, new FileBody(parameter.getFile(key))); } return post(parameter); }
From source file:com.willowtreeapps.uploader.testflight.TestFlightUploader.java
public Map upload(UploadRequest ur) throws IOException, org.json.simple.parser.ParseException { DefaultHttpClient httpClient = new DefaultHttpClient(); HttpHost targetHost = new HttpHost(HOST); HttpPost httpPost = new HttpPost(POST); FileBody fileBody = new FileBody(ur.file); MultipartEntity entity = new MultipartEntity(); entity.addPart("api_token", new StringBody(ur.apiToken)); entity.addPart("team_token", new StringBody(ur.teamToken)); entity.addPart("notes", new StringBody(ur.buildNotes)); entity.addPart("file", fileBody); if (ur.dsymFile != null) { FileBody dsymFileBody = new FileBody(ur.dsymFile); entity.addPart("dsym", dsymFileBody); }/*from w w w .j a va2 s. c om*/ if (ur.lists.length() > 0) { entity.addPart("distribution_lists", new StringBody(ur.lists)); } entity.addPart("notify", new StringBody(ur.notifyTeam ? "True" : "False")); entity.addPart("replace", new StringBody(ur.replace ? "True" : "False")); httpPost.setEntity(entity); return this.send(ur, httpClient, targetHost, httpPost); }
From source file:com.ls.http.base.handler.multipart.FileMultipartEntityPart.java
@Override public ContentBody getContentBody() { return new FileBody(this.value); }
From source file:org.openmrs.client.net.volley.wrappers.MultiPartRequest.java
private void buildMultiPartEntity() { entity.addPart(FILE_PART_NAME, new FileBody(mFilePart)); }
From source file:io.fabric8.maven.support.Apps.java
/** * Posts a file to the git repository//from www . ja va2 s . co m */ public static HttpResponse postFileToGit(File file, String user, String password, String consoleUrl, String branch, String path, Logger logger) throws URISyntaxException, IOException { HttpClientBuilder builder = HttpClients.custom(); if (Strings.isNotBlank(user) && Strings.isNotBlank(password)) { CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope("localhost", 443), new UsernamePasswordCredentials(user, password)); builder = builder.setDefaultCredentialsProvider(credsProvider); } CloseableHttpClient client = builder.build(); try { String url = consoleUrl; if (!url.endsWith("/")) { url += "/"; } url += "git/"; url += branch; if (!path.startsWith("/")) { url += "/"; } url += path; logger.info("Posting App Zip " + file.getName() + " to " + url); URI buildUrl = new URI(url); HttpPost post = new HttpPost(buildUrl); // use multi part entity format FileBody zip = new FileBody(file); HttpEntity entity = MultipartEntityBuilder.create().addPart(file.getName(), zip).build(); post.setEntity(entity); // post.setEntity(new FileEntity(file)); HttpResponse response = client.execute(URIUtils.extractHost(buildUrl), post); logger.info("Response: " + response); if (response != null) { int statusCode = response.getStatusLine().getStatusCode(); if (statusCode < 200 || statusCode >= 300) { throw new IllegalStateException("Failed to post App Zip to: " + url + " " + response); } } return response; } finally { Closeables.closeQuietly(client); } }
From source file:com.codota.uploader.Uploader.java
private void uploadFile(File file, String uploadUrl) throws IOException { HttpPut putRequest = new HttpPut(uploadUrl); MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); builder.addPart("code", new FileBody(file)); final HttpEntity entity = builder.build(); putRequest.setEntity(entity);//from w w w.j av a2 s . c om putRequest.setHeader("enctype", "multipart/form-data"); putRequest.setHeader("authorization", "bearer " + token); httpClient.execute(putRequest, new UploadResponseHandler()); }
From source file:com.gorillalogic.monkeytalk.server.tests.MultipartTest.java
@Test public void testMultipart() throws IOException, JSONException { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://localhost:" + PORT + "/"); File image = new File("resources/test/base.png"); FileBody imagePart = new FileBody(image); StringBody messagePart = new StringBody("some message"); MultipartEntity req = new MultipartEntity(); req.addPart("image", imagePart); req.addPart("message", messagePart); httppost.setEntity(req);/*from w w w . j a v a 2s .c om*/ ImageEchoServer server = new ImageEchoServer(PORT); HttpResponse response = httpclient.execute(httppost); server.stop(); HttpEntity resp = response.getEntity(); assertThat(resp.getContentType().getValue(), is("application/json")); // sweet one-liner to convert an inputstream to a string from stackoverflow: // http://stackoverflow.com/questions/309424/in-java-how-do-i-read-convert-an-inputstream-to-a-string String out = new Scanner(resp.getContent()).useDelimiter("\\A").next(); JSONObject json = new JSONObject(out); String base64 = Base64.encodeFromFile("resources/test/base.png"); assertThat(json.getString("screenshot"), is(base64)); assertThat(json.getBoolean("imageEcho"), is(true)); }
From source file:com.collaide.fileuploader.requests.repository.FilesRequest.java
/** * send a file on the server/*from www . j a va2 s . c o m*/ * * @param file the file to send * @param id the id of the folder (on the server) to send the file. If the * id is equal to zero, the file is send to the root repository */ public void create(File file, int id) { HttpPost httppost = getHttpPostForCreate(); FileBody bin = new FileBody(file); MultipartEntityBuilder reqEntity = MultipartEntityBuilder.create().addPart("repo_file[file]", bin) .addTextBody("authenticity_token", CurrentUser.getUser().getCsrf()); if (id != 0) { reqEntity.addTextBody("repo_file[id]", String.valueOf(id)); } httppost.setEntity(reqEntity.build()); httppost.setHeader("X-CSRF-Token", CurrentUser.getUser().getCsrf()); SendFileThread sendFile = new SendFileThread(httppost, getHttpClient()); sendFile.start(); getSendFileList().add(sendFile); if (getSendFileList().size() >= getMaxConnection()) { terminate(); } }
From source file:uf.edu.uploadTraces.java
boolean sendFile(String Filename) { boolean success = false; HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(con.getResources().getString((R.string.uploadURL))); FileBody bin = new FileBody(new File(Filename)); try {// w ww . java 2 s. com MultipartEntity reqEntity = new MultipartEntity(); reqEntity.addPart("filename", bin); //reqEntity.addPart("comment", comment); httppost.setEntity(reqEntity); HttpResponse response = httpclient.execute(httppost); HttpEntity resEntity = response.getEntity(); Log.i("iTrust", resEntity.toString()); success = true; //save the last upload time pres = con.getSharedPreferences("iTrust", 0); SharedPreferences.Editor ed = pres.edit(); ed.putLong("LastUploadTime", System.currentTimeMillis() / 1000); ed.commit(); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return success; }