MultipartEntity reqEntity = new MultipartEntity(); // add your ContentBody fields as normal... // Now, pull out the contents of everything you've added and set it as the payload ByteArrayOutputStream bos = new ByteArrayOutputStream((int)reqEntity.getContentLength()); reqEntity.writeTo(bos); oAuthReq.addPayload(bos.toByteArray()); // Finally, set the Content-type header (with the boundary marker): Header contentType = reqEntity.getContentType(); oAuthReq.addHeader(contentType.getName(), contentType.getValue()); // Sign and send like normal: service.signRequest(new Token(oAuthToken, oAuthSecret), oAuthReq); Response oauthResp = oAuthReq.send();
String url="<Your URL>"; String fileName="<Your file>"; HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(url); FileBody fileContent= new FileBody(new File(fileName)); StringBody comment = new StringBody("Filename: " + fileName); MultipartEntity reqEntity = new MultipartEntity(); reqEntity.addPart("file", fileContent); httppost.setEntity(reqEntity); System.out.println("post length"+reqEntity.getContentLength()); HttpResponse response = httpclient.execute(httppost); HttpEntity resEntity = response.getEntity();
ServletResponse httpResponse = ctx.getResponse(); ResponseFacade rf = (ResponseFacade) httpResponse; httpResponse.setCharacterEncoding("UTF-8"); httpResponse.setContentType("multipart/mixed"); MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE, "SEPERATOR_STRING",Charset.forName("UTF-8")); entity.addPart("json", new StringBody(CMD + "#" + content, "text/plain", Charset.forName("UTF-8"))); entity.addPart("image", new ByteArrayBody(data, "image/jpeg", "file")); httpResponse.setContentLength((int) entity.getContentLength()); entity.writeTo(httpResponse.getOutputStream()); ctx.complete();
System.out.println("result : " + multipart.getContentLength()); HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(CommunicatorUrl.ADD_INCIDENT);
public class TryFile { public static void main(String[] ar) throws HttpException, IOException, URISyntaxException { // TODO Auto-generated method stub TryFile t=new TryFile(); t.method(); } public void method() throws HttpException, IOException, URISyntaxException { String url="<your url>"; String fileName="<your file name>"; HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(url); FileBody fileContent= new FileBody(new File(fileName)); StringBody comment = new StringBody("Filename: " + fileName); MultipartEntity reqEntity = new MultipartEntity(); reqEntity.addPart("file", fileContent); httppost.setEntity(reqEntity); System.out.println("post length"+reqEntity.getContentLength()); HttpResponse response = httpclient.execute(httppost); HttpEntity resEntity = response.getEntity(); System.out.println("end"+resEntity.getContentLength()); } }
conn.addRequestProperty("Content-length", reqEntity.getContentLength() + ""); conn.addRequestProperty(reqEntity.getContentType().getName(), reqEntity.getContentType().getValue()); OutputStream os = conn.getOutputStream();
conn.addRequestProperty("Content-length", reqEntity.getContentLength() + ""); conn.addRequestProperty(reqEntity.getContentType().getName(), reqEntity.getContentType().getValue()); OutputStream os = conn.getOutputStream();
if (reply == 200) { mSize = entity.getContentLength(); Log.i(TAG, "Uploaded " + file + ": Server reply " + reply); return UploadResult.OK;
totalSize = entity.getContentLength();
totalSize = entity.getContentLength();
totalSize = entity.getContentLength(); post.addHeader("user_id", Session.GetInstance(MainActivity.this).getUserDetail().getUserid()); post.addHeader("device_id", MainActivity.GetDeviceId(MainActivity.this).toString());
totalSize = entity.getContentLength();
multipartEntity.addPart("avatar",new ByteArrayBody(data, "trackImage")); totalSize = multipartEntity.getContentLength(); post.setEntity(multipartEntity); response = httpclient.execute(post);
entity.addPart("PARAMS", new StringBody(request)); long length = entity.getContentLength(); // will force it to