Filebody in java
Java
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
FileBody bin = new FileBody(new File(fileName));
StringBody comment = new StringBody("Filename: " + fileName);
MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("bin", bin);
reqEntity.addPart("comment", comment);
httppost.setEntity(reqEntity);
HttpResponse response = httpclient.execute(httppost);
HttpEntity resEntity = response.getEntity();
public static void postFile(String fileName) throws Exception {//fileName is path+filename of picture
String url_upload_image = "http://url-to-api/upload_photo.php";
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(url_upload_image);
MultipartEntityBuilder multipartEntity = MultipartEntityBuilder
.create();
multipartEntity.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
multipartEntity.addPart("file", new FileBody(new File(fileName)));
post.addHeader("id", id);//id is anything as you may need
post.setEntity(multipartEntity.build());
HttpResponse response = client.execute(post);
HttpEntity entity = response.getEntity();
entity.consumeContent();
client.getConnectionManager().shutdown();
}
Also in Java:
- Title
- transformer un string en Biginteger java
- Category
- Java
- Title
- declareing a variable in java
- Category
- Java
- Title
- array of objects in java
- Category
- Java
- Title
- java empty array
- Category
- Java
- Title
- java list get first element
- Category
- Java
- Title
- demo java file
- Category
- Java
- Title
- java min function
- Category
- Java
- Title
- java read lines from file
- Category
- Java
- Title
- cannot fit requested classes in a single dex file
- Category
- Java
- Title
- declare bufferedreader java
- Category
- Java
- Title
- Java int to roman
- Category
- Java
- Title
- java letter alphabet index
- Category
- Java
- Title
- Please ensure that your JAVA_HOME points to a valid Java SDK. You are currently pointing to: /usr/lib/jvm/java-13-oracle
- Category
- Java
- Title
- how to print the map in java
- Category
- Java
- Title
- arraylist set method
- Category
- Java
- Title
- string equality in java
- Category
- Java
- Title
- equls en java
- Category
- Java
- Title
- array in java stack overflow
- Category
- Java
- Title
- how to add all list elements at once in java
- Category
- Java
- Title
- nth prime number java
- Category
- Java
- Title
- java how to stop code
- Category
- Java
- Title
- capacitor-android. Unfortunately you can't have non-Gradle Java modules and Android-Gradle modules in one project
- Category
- Java
- Title
- how to add an object to a list of objects in java
- Category
- Java
- Title
- Filebody in java
- Category
- Java
- Title
- displaying an arraylist in java
- Category
- Java
- Title
- java calendar add minutes
- Category
- Java
- Title
- log4j with spring boot restful services
- Category
- Java
- Title
- hide elements android
- Category
- Java
- Title
- math minimum java
- Category
- Java
- Title
- java final modifier on method
- Category
- Java
- Title
- java lerp
- Category
- Java
- Title
- print hello world in java
- Category
- Java
- Title
- room insert and return id
- Category
- Java
- Title
- java swing timer sleep
- Category
- Java
- Title
- bukkit java connect player to another server in bungeecord
- Category
- Java
- Title
- déclarer un tableau en java
- Category
- Java
- Title
- libgdx move camera with touch
- Category
- Java
- Title
- raspberry stackexchange how to install the java jdk
- Category
- Java
- Title
- action on long press of edit edittext
- Category
- Java
- Title
- most common element in list java
- Category
- Java
- Title
- how to add an image to a gui in java windowbuilder
- Category
- Java
- Title
- even or odd in java
- Category
- Java
- Title
- java create folder
- Category
- Java
- Title
- create jdbc connection in java
- Category
- Java
- Title
- java script print date in YYYY-MM-DD format
- Category
- Java
- Title
- java integer compareto
- Category
- Java
- Title
- separateur JMenu swing java
- Category
- Java
- Title
- android BottomSheetDialogFragment not opening fully on landscape
- Category
- Java
- Title
- floor in java
- Category
- Java
- Title
- how to remove spaces from an array in java
- Category
- Java
- Title
- read int from keyboard java
- Category
- Java
- Title
- java insert new line in string
- Category
- Java
- Title
- Java nested array hashcode
- Category
- Java
- Title
- java for each
- Category
- Java
- Title
- format localdate java
- Category
- Java
- Title
- import collections in java
- Category
- Java
- Title
- comparable on a generic class java
- Category
- Java
- Title
- LocalRegistry java rebind() java8
- Category
- Java
- Title
- java string indexof
- Category
- Java
- Title
- how to read file from assets folder in android
- Category
- Java
- Title
- java check if directory exists
- Category
- Java
- Title
- java previous permutation
- Category
- Java
- Title
- JFrame text java
- Category
- Java
- Title
- set color of text for jlabel
- Category
- Java
- Title
- arraylist to array java
- Category
- Java
- Title
- Java how to handle HTTP GET request after establishing TCP connection
- Category
- Java
- Title
- check last character of string java
- Category
- Java
- Title
- getordefault java
- Category
- Java
- Title
- null pointer exception java
- Category
- Java
- Title
- how to check the end of a string java
- Category
- Java
- Title
- java square a number
- Category
- Java
- Title
- android notification addaction example
- Category
- Java
- Title
- close searchview android java
- Category
- Java
- Title
- how to find the intersection of two rectangles in java
- Category
- Java
- Title
- org.springframework.orm.jpa.EntityManagerHolder cannot be cast to org.springframework.orm.hibernate5.SessionHolder
- Category
- Java
- Title
- java string to character stream
- Category
- Java
- Title
- using get in map in java
- Category
- Java
- Title
- compile java to jar in mac
- Category
- Java
- Title
- java get current date without time
- Category
- Java
- Title
- loop through java object
- Category
- Java
- Title
- mettre caractère de string en majuscule java
- Category
- Java
- Title
- what is java plug-in
- Category
- Java
- Title
- add two numbers bitwise
- Category
- Java
- Title
- android create notification
- Category
- Java
- Title
- how to change actionbar color in android programmatically
- Category
- Java
- Title
- BoxLayout java
- Category
- Java
- Title
- non primitive data types in java
- Category
- Java
- Title
- set java
- Category
- Java
- Title
- iterate through an arraylist java
- Category
- Java
- Title
- java while
- Category
- Java
- Title
- add a value to a list java in java hashmap
- Category
- Java
- Title
- java while loop break
- Category
- Java
- Title
- java.lang.long cannot be cast to java.lang.integer
- Category
- Java
- Title
- java mysql springboot jpa stackoverflow
- Category
- Java
- Title
- inheritance setter and getter in java
- Category
- Java
- Title
- indexof java
- Category
- Java
- Title
- how to create a linked list in java
- Category
- Java
- Title
- java constructor
- Category
- Java
- Title
- reading string after double in java
- Category
- Java
- Title
- find a substring in a string java
- Category
- Java