Tabnine Logo
MultipartEntity.<init>
Code IndexAdd Tabnine to your IDE (free)

How to use
org.apache.http.entity.mime.MultipartEntity
constructor

Best Java code snippets using org.apache.http.entity.mime.MultipartEntity.<init> (Showing top 20 results out of 486)

Refine searchRefine arrow

  • MultipartEntity.addPart
  • HttpPost.setEntity
  • DefaultHttpClient.<init>
  • HttpClient.execute
  • HttpPost.<init>
  • FileBody.<init>
origin: stackoverflow.com

 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();
origin: stackoverflow.com

 MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("someParam", "someValue");
reqEntity.addPart("someFile", new FileBody("/some/file"));
....

httpost.setEntity(reqEntity);
origin: stackoverflow.com

HttpPost req = new HttpPost(composeTargetUrl());
 MultipartEntity entity = new MultipartEntity();
 entity.addPart(POST_IMAGE_VAR_NAME, new FileBody(toUpload));
 try {
   entity.addPart(POST_SESSION_VAR_NAME, new StringBody(uploadSessionId));
 } catch (UnsupportedEncodingException e) {
   throw new RuntimeException(e);
 }
 req.setEntity(entity);
origin: stackoverflow.com

 HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(uploadUrlReturnedFromStep2);

FileBody fileBody  = new FileBody(thumbnailFile);
MultipartEntity reqEntity = new MultipartEntity();

reqEntity.addPart("file", fileBody);

httppost.setEntity(reqEntity);
HttpResponse response = httpclient.execute(httppost)
origin: stackoverflow.com

private MultipartEntity entity = new MultipartEntity();
  entity.addPart(FILE_PART_NAME, new FileBody(mFilePart));
  try
    entity.addPart(STRING_PART_NAME, new StringBody(mStringPart));
origin: stackoverflow.com

 HttpClient httpclient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);

FileBody uploadFilePart = new FileBody(uploadFile);
MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("upload-file", uploadFilePart);
httpPost.setEntity(reqEntity);

HttpResponse response = httpclient.execute(httpPost);
origin: stackoverflow.com

 httppost = new HttpPost(URL);
MultipartEntity entity = new MultipartEntity();
entity.addPart("title", new StringBody("position.csv", Charset.forName("UTF-8")));
File myFile = new File(Environment.getExternalStorageDirectory(), file);
FileBody fileBody = new FileBody(myFile);
entity.addPart("file", fileBody);
httppost.setEntity(entity);
httppost.getParams().setParameter("project", id);
origin: stackoverflow.com

 HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(url);

MultipartEntity entity = new MultipartEntity();
entity.addPart("file", new FileBody(file));
post.setEntity(entity);

HttpResponse response = client.execute(post);
// ...
origin: stackoverflow.com

MultipartEntity reqEntity = new MultipartEntity();
 try {
   reqEntity.addPart("email", new StringBody(email));
   reqEntity.addPart("image", new FileBody(new File(imagePath)));
   reqEntity.addPart("img_desc", new StringBody(img_desc));
   reqEntity.addPart("amount", new StringBody(amount));
   reqEntity.addPart("request_type", new StringBody("INSERT"));
 } catch (UnsupportedEncodingException e) {
   e.printStackTrace();
 }
origin: stackoverflow.com

 MultipartEntity multipart = new MultipartEntity();
File file = new File("/filepath");  // File with some location (filepath)
Charset chars = Charset.forName("UTF-8"); // Setting up the encoding
FileBody fileB = new FileBody(file); // Create a new FileBody with the above mentioned file
multipart.addPart("data", fileB); // Add the part to my MultipartEntity. "data" is parameter name for the file
StringBody stringB;  // Now lets add some extra information in a StringBody
try {
  stringB = new StringBody("I am the caption of the file",chars);  // Adding the content to the StringBody and setting up the encoding
  multipart.addPart("caption", stringB); // Add the part to my MultipartEntity
} catch (UnsupportedEncodingException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
}

HttpPost post = new HttpPost(url); // Setting up a HTTP Post method with the target url
post.setEntity(multipart); // Setting the multipart Entity to the post method
HttpResponse resp = client.execute(post);  // Using some HttpClient (I'm using DefaultHttpClient) to execute the post method and receive the response
origin: rcarz/jira-client

private JSON request(HttpEntityEnclosingRequestBase req, File file)
  throws RestException, IOException {
  if (file != null) {
    File fileUpload = file;
    req.setHeader("X-Atlassian-Token", "nocheck");
    MultipartEntity ent = new MultipartEntity();
    ent.addPart("file", new FileBody(fileUpload));
    req.setEntity(ent);
  }
  return request(req);
}
origin: ninjaframework/ninja

public String uploadFile(String url, String paramName, File fileToUpload) {
  String response = null;
  try {
    httpClient.getParams().setParameter(
        CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    HttpPost post = new HttpPost(url);
    MultipartEntity entity = new MultipartEntity(
        HttpMultipartMode.BROWSER_COMPATIBLE);
    // For File parameters
    entity.addPart(paramName, new FileBody((File) fileToUpload));
    post.setEntity(entity);
    // Here we go!
    response = EntityUtils.toString(httpClient.execute(post)
        .getEntity(), "UTF-8");
    post.releaseConnection();
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
  return response;
}

origin: ninjaframework/ninja

public String uploadFiles(String url, String[] paramNames, File[] fileToUploads) {
  String response = null;
  try {
    httpClient.getParams().setParameter(
        CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    HttpPost post = new HttpPost(url);
    MultipartEntity entity = new MultipartEntity(
        HttpMultipartMode.BROWSER_COMPATIBLE);
    // For File parameters
    for (int i=0; i<paramNames.length; i++) {
      
      entity.addPart(paramNames[i], new FileBody(fileToUploads[i]));
    }
    post.setEntity(entity);
    // Here we go!
    response = EntityUtils.toString(httpClient.execute(post)
        .getEntity(), "UTF-8");
    post.releaseConnection();
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
  return response;
}
origin: stackoverflow.com

HttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
HttpPost httppost = new HttpPost("http://localhost:9001/upload.php");
File file = new File("c:/TRASH/zaba_1.jpg");
MultipartEntity mpEntity = new MultipartEntity();
ContentBody cbFile = new FileBody(file, "image/jpeg");
mpEntity.addPart("userfile", cbFile);
httppost.setEntity(mpEntity);
System.out.println("executing request " + httppost.getRequestLine());
HttpResponse response = httpclient.execute(httppost);
HttpEntity resEntity = response.getEntity();
origin: ninjaframework/ninja

public String uploadFileWithForm(String url, String paramName, File fileToUpload, Map<String, String> formParameters) {
  String response = null;
  try {
    httpClient.getParams().setParameter(
        CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    HttpPost post = new HttpPost(url);
    MultipartEntity entity = new MultipartEntity(
        HttpMultipartMode.BROWSER_COMPATIBLE);
    // For File parameters
    entity.addPart(paramName, new FileBody((File) fileToUpload));
    // add form parameters:
    if (formParameters != null) {
      for (Entry<String, String> parameter : formParameters
          .entrySet()) {
        entity.addPart(parameter.getKey(), new StringBody(parameter.getValue()));
      }
    }
    
    post.setEntity(entity);
    // Here we go!
    response = EntityUtils.toString(httpClient.execute(post)
        .getEntity(), "UTF-8");
    post.releaseConnection();
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
  return response;
}
origin: stackoverflow.com

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(YOUR_URL);
FileBody filebodyVideo = new FileBody(new File(videoPath));
StringBody title = new StringBody("Filename: " + videoPath);
StringBody description = new StringBody("This is a description of the video");
MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("videoFile", filebodyVideo);
reqEntity.addPart("title", title);
reqEntity.addPart("description", description);
httppost.setEntity(reqEntity);
HttpResponse response = httpclient.execute( httppost );
HttpEntity resEntity = response.getEntity( );
origin: kaaproject/kaa

@Override
public byte[] executeHttpRequest(String uri, LinkedHashMap<String, byte[]> entity,
                 boolean verifyResponse) throws Exception { //NOSONAR
 byte[] responseDataRaw = null;
 method = new HttpPost(url + uri);
 MultipartEntity requestEntity = new MultipartEntity();
 for (String key : entity.keySet()) {
  requestEntity.addPart(key, new ByteArrayBody(entity.get(key), null));
 }
 method.setEntity(requestEntity);
 if (!Thread.currentThread().isInterrupted()) {
  LOG.debug("Executing request {}", method.getRequestLine());
  HttpResponse response = httpClient.execute(method);
  try {
   LOG.debug("Received {}", response.getStatusLine());
   int status = response.getStatusLine().getStatusCode();
   if (status >= 200 && status < 300) {
    responseDataRaw = getResponseBody(response, verifyResponse);
   } else {
    throw new TransportException(status);
   }
  } finally {
   method = null;
  }
 } else {
  method = null;
  throw new InterruptedException();
 }
 return responseDataRaw;
}
origin: stackoverflow.com

MultipartEntity entity = new MultipartEntity();
 entity.addPart("file", new FileBody(file));
 HttpPost request = new HttpPost(url);
 request.setEntity(entity);
 HttpClient client = new DefaultHttpClient();
 HttpResponse response = client.execute(request);
origin: stackoverflow.com

 MultipartEntity entity = new MultipartEntity();
entity.addPart("foo", new InputStreamBody(new ByteArrayInputStream(fooGzippedBytes), "foo.txt"));

HttpPost post = new HttpPost("http://example.com/some");
post.setEntity(entity);

HttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(post);
// ...
origin: stackoverflow.com

 HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.tumblr.com/api/write");

try 
{
  MultipartEntity entity = new MultipartEntity();
  entity.addPart("type",new StringBody("yourstring"));
  httppost.setEntity(entity);
  HttpResponse response = httpclient.execute(httppost);
} 
catch (ClientProtocolException e) 
{ } 
catch (IOException e) 
{ }
org.apache.http.entity.mimeMultipartEntity<init>

Javadoc

Creates an instance using mode HttpMultipartMode#STRICT

Popular methods of MultipartEntity

  • addPart
  • writeTo
  • getContentType
  • getContentLength
  • isStreaming
  • consumeContent
  • generateBoundary
  • generateContentType
  • getEntity
  • isRepeatable

Popular in Java

  • Reading from database using SQL prepared statement
  • addToBackStack (FragmentTransaction)
  • getExternalFilesDir (Context)
  • compareTo (BigDecimal)
  • GregorianCalendar (java.util)
    GregorianCalendar is a concrete subclass of Calendarand provides the standard calendar used by most
  • StringTokenizer (java.util)
    Breaks a string into tokens; new code should probably use String#split.> // Legacy code: StringTo
  • BlockingQueue (java.util.concurrent)
    A java.util.Queue that additionally supports operations that wait for the queue to become non-empty
  • ZipFile (java.util.zip)
    This class provides random read access to a zip file. You pay more to read the zip file's central di
  • Servlet (javax.servlet)
    Defines methods that all servlets must implement. A servlet is a small Java program that runs within
  • JLabel (javax.swing)
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now