org.apache.http.entity.mime.content.ContentBody Java Examples
The following examples show how to use
org.apache.http.entity.mime.content.ContentBody.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpBodyPart.java From ats-framework with Apache License 2.0 | 7 votes |
ContentBody constructContentBody() throws UnsupportedEncodingException { ContentType contentTypeObject = constructContentTypeObject(); if (filePath != null) { // FILE part if (contentTypeObject != null) { return new FileBody(new File(filePath), contentTypeObject); } else { return new FileBody(new File(filePath)); } } else if (content != null) { // TEXT part if (contentTypeObject != null) { return new StringBody(content, contentTypeObject); } else { return new StringBody(content, ContentType.TEXT_PLAIN); } } else { // BYTE ARRAY part if (contentTypeObject != null) { return new ByteArrayBody(this.fileBytes, contentTypeObject, fileName); } else { return new ByteArrayBody(this.fileBytes, fileName); } } }
Example #2
Source File: Remote.java From HongsCORE with MIT License | 7 votes |
private static void buildPart(MultipartEntityBuilder part, String n, Object v) { if (v instanceof ContentBody) { part.addPart(n, (ContentBody) v); } else if (v instanceof File) { part.addBinaryBody(n , (File) v); } else if (v instanceof byte[]) { part.addBinaryBody(n , (byte[]) v); } else if (v instanceof InputStream) { part.addBinaryBody(n , (InputStream) v); } else { part.addTextBody(n , String.valueOf(v)); } }
Example #3
Source File: ShareSendUploaderPlugin.java From neembuu-uploader with GNU General Public License v3.0 | 6 votes |
private static void fileUpload() throws IOException { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(postURL); file = new File("h:/install.txt"); MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); ContentBody cbFile = new FileBody(file); mpEntity.addPart("Filename", new StringBody(file.getName())); mpEntity.addPart("Filedata", cbFile); httppost.setEntity(mpEntity); System.out.println("executing request " + httppost.getRequestLine()); System.out.println("Now uploading your file into sharesend.com"); HttpResponse response = httpclient.execute(httppost); HttpEntity resEntity = response.getEntity(); System.out.println(response.getStatusLine()); if (resEntity != null) { uploadresponse = EntityUtils.toString(resEntity); } System.out.println("Upload Response : " + uploadresponse); System.out.println("Download Link : http://sharesend.com/" + uploadresponse); httpclient.getConnectionManager().shutdown(); }
Example #4
Source File: OTATest.java From blynk-server with GNU General Public License v3.0 | 6 votes |
@Test public void testAuthorizationFailed() throws Exception { HttpPost post = new HttpPost(httpsAdminServerUrl + "/ota/start?token=" + 123); post.setHeader(HttpHeaderNames.AUTHORIZATION.toString(), "Basic " + Base64.getEncoder().encodeToString("123:123".getBytes())); String fileName = "test.bin"; InputStream binFile = OTATest.class.getResourceAsStream("/static/ota/" + fileName); ContentBody fileBody = new InputStreamBody(binFile, ContentType.APPLICATION_OCTET_STREAM, fileName); MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); builder.addPart("upfile", fileBody); HttpEntity entity = builder.build(); post.setEntity(entity); try (CloseableHttpResponse response = httpclient.execute(post)) { assertEquals(403, response.getStatusLine().getStatusCode()); String error = TestUtil.consumeText(response); assertNotNull(error); assertEquals("Authentication failed.", error); } }
Example #5
Source File: GotenbergClientService.java From estatio with Apache License 2.0 | 6 votes |
@Programmatic public byte[] convertToPdf( final byte[] docxBytes, final String url) { try (CloseableHttpClient httpclient = HttpClients.createDefault()) { final HttpPost httpPost = new HttpPost(url); ContentBody bin = new ByteArrayBody(docxBytes, "dummy.docx"); HttpEntity reqEntity = MultipartEntityBuilder.create() .addPart("files", bin) .build(); httpPost.setEntity(reqEntity); try (CloseableHttpResponse response = httpclient.execute(httpPost)) { HttpEntity resEntity = response.getEntity(); return resEntity != null ? EntityUtils.toByteArray(resEntity) : null; } } catch (IOException e) { throw new RuntimeException(e); } }
Example #6
Source File: OTATest.java From blynk-server with GNU General Public License v3.0 | 6 votes |
@Test public void testOTAWrongToken() throws Exception { HttpPost post = new HttpPost(httpsAdminServerUrl + "/ota/start?token=" + 123); post.setHeader(HttpHeaderNames.AUTHORIZATION.toString(), "Basic " + Base64.getEncoder().encodeToString(auth)); String fileName = "test.bin"; InputStream binFile = OTATest.class.getResourceAsStream("/static/ota/" + fileName); ContentBody fileBody = new InputStreamBody(binFile, ContentType.APPLICATION_OCTET_STREAM, fileName); MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); builder.addPart("upfile", fileBody); HttpEntity entity = builder.build(); post.setEntity(entity); try (CloseableHttpResponse response = httpclient.execute(post)) { assertEquals(400, response.getStatusLine().getStatusCode()); String error = TestUtil.consumeText(response); assertNotNull(error); assertEquals("Invalid token.", error); } }
Example #7
Source File: MultipartForm.java From iaf with Apache License 2.0 | 6 votes |
/** * Determines the total length of the multipart content (content length of * individual parts plus that of extra elements required to delimit the parts * from one another). If any of the @{link BodyPart}s contained in this object * is of a streaming entity of unknown length the total length is also unknown. * <p> * This method buffers only a small amount of data in order to determine the * total length of the entire entity. The content of individual parts is not * buffered. * </p> * * @return total length of the multipart entity if known, {@code -1} otherwise. */ public long getTotalLength() { long contentLen = 0; for (final FormBodyPart part: getBodyParts()) { final ContentBody body = part.getBody(); final long len = body.getContentLength(); if (len >= 0) { contentLen += len; } else { return -1; } } final ByteArrayOutputStream out = new ByteArrayOutputStream(); try { doWriteTo(out, false); final byte[] extra = out.toByteArray(); return contentLen + extra.length; } catch (final IOException ex) { // Should never happen return -1; } }
Example #8
Source File: ZohoDocsUploaderPlugin.java From neembuu-uploader with GNU General Public License v3.0 | 6 votes |
public static void fileUpload() throws IOException { HttpClient httpclient = new DefaultHttpClient(); httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); file = new File("C:\\Documents and Settings\\dinesh\\Desktop\\GeDotttUploaderPlugin.java"); HttpPost httppost = new HttpPost("https://docs.zoho.com/uploadsingle.do?isUploadStatus=false&folderId=0&refFileElementId=refFileElement0"); httppost.setHeader("Cookie", cookies.toString()); MultipartEntity mpEntity = new MultipartEntity(); ContentBody cbFile = new FileBody(file); mpEntity.addPart("multiupload_file", cbFile); httppost.setEntity(mpEntity); System.out.println("Now uploading your file into zoho docs..........................."); HttpResponse response = httpclient.execute(httppost); HttpEntity resEntity = response.getEntity(); System.out.println(response.getStatusLine()); if (resEntity != null) { String tmp = EntityUtils.toString(resEntity); // System.out.println(tmp); if(tmp.contains("File Uploaded Successfully")) System.out.println("File Uploaded Successfully"); } // uploadresponse = response.getLastHeader("Location").getValue(); // System.out.println("Upload response : " + uploadresponse); }
Example #9
Source File: UGotFileUploaderPlugin.java From neembuu-uploader with GNU General Public License v3.0 | 6 votes |
private static void fileUpload() throws Exception { DefaultHttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(postURL); file = new File("h:/Sakura haruno.jpg"); MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); ContentBody cbFile = new FileBody(file); mpEntity.addPart("Filename", new StringBody(file.getName())); mpEntity.addPart("Filedata", cbFile); // mpEntity.addPart("server", new StringBody(server)); httppost.setEntity(mpEntity); System.out.println("executing request " + httppost.getRequestLine()); System.out.println("Now uploading your file into ugotfile.com"); HttpResponse response = httpclient.execute(httppost); System.out.println(response.getStatusLine()); if (response != null) { uploadresponse = EntityUtils.toString(response.getEntity()); } System.out.println("Upload Response : " + uploadresponse); downloadlink = parseResponse(uploadresponse, "[\"", "\""); downloadlink = downloadlink.replaceAll("\\\\/", "/"); deletelink = parseResponse(uploadresponse, "\",\"", "\""); deletelink = deletelink.replaceAll("\\\\/", "/"); System.out.println("Download Link : " + downloadlink); System.out.println("Delete Link : " + deletelink); }
Example #10
Source File: DivShareUploaderPlugin.java From neembuu-uploader with GNU General Public License v3.0 | 6 votes |
private static void fileUpload() throws Exception { file = new File("C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Sunset.jpg"); httpclient = new DefaultHttpClient(); //http://upload3.divshare.com/cgi-bin/upload.cgi?sid=8ef15852c69579ebb2db1175ce065ba6 HttpPost httppost = new HttpPost(downURL + "cgi-bin/upload.cgi?sid=" + sid); MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); ContentBody cbFile = new FileBody(file); mpEntity.addPart("file[0]", cbFile); httppost.setEntity(mpEntity); System.out.println("executing request " + httppost.getRequestLine()); System.out.println("Now uploading your file into divshare.com"); HttpResponse response = httpclient.execute(httppost); HttpEntity resEntity = response.getEntity(); System.out.println(response.getStatusLine()); System.out.println(EntityUtils.toString(resEntity)); }
Example #11
Source File: OTATest.java From blynk-server with GNU General Public License v3.0 | 6 votes |
@Test public void basicOTAForNonExistingSingleUser() throws Exception { HttpPost post = new HttpPost(httpsAdminServerUrl + "/ota/[email protected]"); post.setHeader(HttpHeaderNames.AUTHORIZATION.toString(), "Basic " + Base64.getEncoder().encodeToString(auth)); String fileName = "test.bin"; InputStream binFile = OTATest.class.getResourceAsStream("/static/ota/" + fileName); ContentBody fileBody = new InputStreamBody(binFile, ContentType.APPLICATION_OCTET_STREAM, fileName); MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); builder.addPart("upfile", fileBody); HttpEntity entity = builder.build(); post.setEntity(entity); try (CloseableHttpResponse response = httpclient.execute(post)) { assertEquals(400, response.getStatusLine().getStatusCode()); String er = TestUtil.consumeText(response); assertNotNull(er); assertEquals("Requested user not found.", er); } }
Example #12
Source File: WuploadUploaderPlugin.java From neembuu-uploader with GNU General Public License v3.0 | 6 votes |
public static void fileUpload() throws IOException { HttpClient httpclient = new DefaultHttpClient(); httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); file = new File("/home/vigneshwaran/dinesh.txt"); HttpPost httppost = new HttpPost(postURL); httppost.setHeader("Cookie", langcookie + ";" + sessioncookie + ";" + mailcookie + ";" + namecookie + ";" + rolecookie + ";" + orderbycookie + ";" + directioncookie + ";"); MultipartEntity mpEntity = new MultipartEntity(); ContentBody cbFile = new FileBody(file); mpEntity.addPart("files[]", cbFile); httppost.setEntity(mpEntity); System.out.println("Now uploading your file into wupload..........................."); HttpResponse response = httpclient.execute(httppost); HttpEntity resEntity = response.getEntity(); System.out.println(response.getStatusLine()); if (response.getStatusLine().getStatusCode() == 302 && response.getFirstHeader("Location").getValue().contains("upload/done/")) { System.out.println("Upload successful :)"); } else { System.out.println("Upload failed :("); } }
Example #13
Source File: UploadBoxUploaderPlugin.java From neembuu-uploader with GNU General Public License v3.0 | 6 votes |
private static void fileUpload() throws Exception { DefaultHttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(postURL); httppost.setHeader("Cookie", sidcookie); file = new File("h:/install.txt"); MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); ContentBody cbFile = new FileBody(file); mpEntity.addPart("filepc", cbFile); mpEntity.addPart("server", new StringBody(server)); httppost.setEntity(mpEntity); System.out.println("executing request " + httppost.getRequestLine()); System.out.println("Now uploading your file into uploadbox.com"); HttpResponse response = httpclient.execute(httppost); System.out.println(response.getStatusLine()); uploadresponse = response.getLastHeader("Location").getValue(); uploadresponse = getData(uploadresponse); downloadlink = parseResponse(uploadresponse, "name=\"loadlink\" id=\"loadlink\" class=\"text\" onclick=\"this.select();\" value=\"", "\""); deletelink = parseResponse(uploadresponse, "name=\"deletelink\" id=\"deletelink\" class=\"text\" onclick=\"this.select();\" value=\"", "\""); System.out.println("Download link " + downloadlink); System.out.println("deletelink : " + deletelink); }
Example #14
Source File: SockShare.java From neembuu-uploader with GNU General Public License v3.0 | 6 votes |
/** * Upload with <a href="http://www.sockshare.com/apidocs.php">API</a>. */ private void apiUpload() throws UnsupportedEncodingException, IOException, Exception{ uploading(); ContentBody cbFile = createMonitoredFileBody(); NUHttpPost httppost = new NUHttpPost(apiURL); MultipartEntity mpEntity = new MultipartEntity(); mpEntity.addPart("file", cbFile); mpEntity.addPart("user", new StringBody(sockShareAccount.username)); mpEntity.addPart("password", new StringBody(sockShareAccount.password)); httppost.setEntity(mpEntity); HttpResponse response = httpclient.execute(httppost); String reqResponse = EntityUtils.toString(response.getEntity()); //NULogger.getLogger().info(reqResponse); if(reqResponse.contains("File Uploaded Successfully")){ gettingLink(); downURL = StringUtils.stringBetweenTwoStrings(reqResponse, "<link>", "</link>"); } else{ //Handle the errors status = UploadStatus.GETTINGERRORS; throw new Exception(StringUtils.stringBetweenTwoStrings(reqResponse, "<message>", "</message>")); } }
Example #15
Source File: ZippyShareUploaderPlugin.java From neembuu-uploader with GNU General Public License v3.0 | 6 votes |
private static void fileUpload() throws IOException { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(postURL); //httppost.setHeader("Cookie", sidcookie+";"+mysessioncookie); file = new File("h:/UploadingdotcomUploaderPlugin.java"); MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); ContentBody cbFile = new FileBody(file); mpEntity.addPart("Filename", new StringBody(file.getName())); mpEntity.addPart("notprivate", new StringBody("false")); mpEntity.addPart("folder", new StringBody("/")); mpEntity.addPart("Filedata", cbFile); httppost.setEntity(mpEntity); System.out.println("executing request " + httppost.getRequestLine()); System.out.println("Now uploading your file into zippyshare.com"); HttpResponse response = httpclient.execute(httppost); HttpEntity resEntity = response.getEntity(); System.out.println(response.getStatusLine()); if (resEntity != null) { uploadresponse = EntityUtils.toString(resEntity); } downloadlink=parseResponse(uploadresponse, "value=\"http://", "\""); downloadlink="http://"+downloadlink; System.out.println("Download Link : "+downloadlink); httpclient.getConnectionManager().shutdown(); }
Example #16
Source File: MegaShareUploaderPlugin.java From neembuu-uploader with GNU General Public License v3.0 | 6 votes |
private static void fileUpload() throws IOException { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(postURL); file = new File("h:/UploadingdotcomUploaderPlugin.java"); MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); ContentBody cbFile = new FileBody(file); mpEntity.addPart("emai", new StringBody("Free")); mpEntity.addPart("upload_range", new StringBody("1")); mpEntity.addPart("upfile_0", cbFile); httppost.setEntity(mpEntity); System.out.println("executing request " + httppost.getRequestLine()); System.out.println("Now uploading your file into MegaShare.com"); HttpResponse response = httpclient.execute(httppost); HttpEntity resEntity = response.getEntity(); uploadresponse = response.getLastHeader("Location").getValue(); System.out.println("Upload response : "+uploadresponse); System.out.println(response.getStatusLine()); httpclient.getConnectionManager().shutdown(); }
Example #17
Source File: MediaFireUploadPlugin.java From neembuu-uploader with GNU General Public License v3.0 | 6 votes |
public static void fileUpload() throws IOException { HttpClient httpclient = new DefaultHttpClient(); httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); HttpPost httppost = new HttpPost(postURL); File file = new File("d:/hai.html"); System.out.println(ukeycookie); httppost.setHeader("Cookie", ukeycookie + ";" + skeycookie + ";" + usercookie); MultipartEntity mpEntity = new MultipartEntity(); ContentBody cbFile = new FileBody(file); mpEntity.addPart("", cbFile); httppost.setEntity(mpEntity); System.out.println("Now uploading your file into mediafire..........................."); HttpResponse response = httpclient.execute(httppost); HttpEntity resEntity = response.getEntity(); System.out.println(response.getStatusLine()); if (resEntity != null) { System.out.println("Getting upload response key value.........."); uploadresponsekey = EntityUtils.toString(resEntity); getUploadResponseKey(); System.out.println("upload resoponse key " + uploadresponsekey); } }
Example #18
Source File: UploadedDotToUploaderPlugin.java From neembuu-uploader with GNU General Public License v3.0 | 5 votes |
private static void fileUpload() throws Exception { DefaultHttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(postURL); // httppost.setHeader("Referer", "https://www.dropbox.com/home/Public"); //httppost.setHeader("Cookie", phpsessioncookie); file = new File("h:\\install.txt"); MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); ContentBody cbFile = new FileBody(file); mpEntity.addPart("Filename", new StringBody(file.getName())); mpEntity.addPart("Filedata", cbFile); httppost.setEntity(mpEntity); System.out.println("executing request " + httppost.getRequestLine()); System.out.println("Now uploading your file into uploaded.to"); HttpResponse response = httpclient.execute(httppost); HttpEntity resEntity = response.getEntity(); System.out.println(response.getStatusLine()); if (resEntity != null) { uploadresponse = EntityUtils.toString(resEntity); } // System.out.println("Upload response : " + uploadresponse); uploadresponse = uploadresponse.substring(0, uploadresponse.indexOf(",")); downloadlink = "http://ul.to/" + uploadresponse; System.out.println("Download link : " + downloadlink); }
Example #19
Source File: FileDenUploaderPlugin.java From neembuu-uploader with GNU General Public License v3.0 | 5 votes |
private static void fileUpload() throws Exception { DefaultHttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://www.fileden.com/upload_old.php"); httppost.setHeader("Cookie", cookies.toString()); file = new File("C:\\Documents and Settings\\dinesh\\Desktop\\ImageShackUploaderPlugin.java"); MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); ContentBody cbFile = new FileBody(file); mpEntity.addPart("Filename", new StringBody(file.getName())); mpEntity.addPart("action", new StringBody("upload")); mpEntity.addPart("upload_to", new StringBody("")); mpEntity.addPart("overwrite_option", new StringBody("overwrite")); mpEntity.addPart("thumbnail_size", new StringBody("small")); mpEntity.addPart("create_img_tags", new StringBody("1")); mpEntity.addPart("file0", cbFile); httppost.setEntity(mpEntity); System.out.println("executing request " + httppost.getRequestLine()); System.out.println("Now uploading your file into fileden"); HttpResponse response = httpclient.execute(httppost); HttpEntity resEntity = response.getEntity(); System.out.println(response.getStatusLine()); if (resEntity != null) { uploadresponse = EntityUtils.toString(resEntity); } System.out.println(uploadresponse); downloadlink = parseResponse(uploadresponse, "'link':'", "'"); System.out.println("Download link : " + downloadlink); httpclient.getConnectionManager().shutdown(); }
Example #20
Source File: FileUploadDownloadClient.java From incubator-pinot with Apache License 2.0 | 5 votes |
private static HttpUriRequest getUploadFileRequest(String method, URI uri, ContentBody contentBody, @Nullable List<Header> headers, @Nullable List<NameValuePair> parameters, int socketTimeoutMs) { // Build the Http entity HttpEntity entity = MultipartEntityBuilder.create().setMode(HttpMultipartMode.BROWSER_COMPATIBLE) .addPart(contentBody.getFilename(), contentBody).build(); // Build the request RequestBuilder requestBuilder = RequestBuilder.create(method).setVersion(HttpVersion.HTTP_1_1).setUri(uri).setEntity(entity); addHeadersAndParameters(requestBuilder, headers, parameters); setTimeout(requestBuilder, socketTimeoutMs); return requestBuilder.build(); }
Example #21
Source File: BayFilesUploaderPlugin.java From neembuu-uploader with GNU General Public License v3.0 | 5 votes |
private static void fileUpload() throws Exception { DefaultHttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(postURL); file = new File("/home/vigneshwaran/Documents/TNEB Online Payment 3.pdf"); MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); ContentBody cbFile = new FileBody(file); mpEntity.addPart("file", cbFile); httppost.setEntity(mpEntity); System.out.println("executing request " + httppost.getRequestLine()); System.out.println("Now uploading your file into bayfiles.com"); HttpResponse response = httpclient.execute(httppost); // HttpEntity resEntity = response.getEntity(); uploadresponse = EntityUtils.toString(response.getEntity()); System.out.println(response.getStatusLine()); // if (resEntity != null) { // uploadresponse = EntityUtils.toString(resEntity); // } // System.out.println("Upload response : " + uploadresponse); downloadlink = parseResponse(uploadresponse, "\"downloadUrl\":\"", "\""); downloadlink = downloadlink.replaceAll("\\\\", ""); deletelink = parseResponse(uploadresponse, "\"deleteUrl\":\"", "\""); deletelink = deletelink.replaceAll("\\\\", ""); System.out.println("Download link : " + downloadlink); System.out.println("Delete link : " + deletelink); }
Example #22
Source File: LetitbitUploaderPlugin.java From neembuu-uploader with GNU General Public License v3.0 | 5 votes |
private static void fileUpload() throws Exception { DefaultHttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(postURL); // httppost.setHeader("Referer", "https://www.dropbox.com/home/Public"); //httppost.setHeader("Cookie", phpsessioncookie); file = new File("h:\\Fantastic face.jpg"); MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); ContentBody cbFile = new FileBody(file); mpEntity.addPart("MAX_FILE_SIZE", new StringBody("2147483647")); mpEntity.addPart("owner", new StringBody("")); mpEntity.addPart("pin", new StringBody(pin)); mpEntity.addPart("base", new StringBody(base)); mpEntity.addPart("host", new StringBody("letitbit.net")); // mpEntity.addPart("filename", new StringBody(file.getName())); mpEntity.addPart("file0", cbFile); // if (login) { // mpEntity.addPart("memail", new StringBody(uploadmailid)); // } httppost.setEntity(mpEntity); System.out.println("executing request " + httppost.getRequestLine()); System.out.println("Now uploading your file into letitbit.net"); HttpResponse response = httpclient.execute(httppost); HttpEntity resEntity = response.getEntity(); System.out.println(response.getStatusLine()); if (resEntity != null) { uploadresponse = EntityUtils.toString(resEntity); } // System.out.println("Upload response : " + uploadresponse); }
Example #23
Source File: LocalhostrUploaderPlugin.java From neembuu-uploader with GNU General Public License v3.0 | 5 votes |
public static void fileUpload() throws IOException { File file = new File("/home/vigneshwaran/VIGNESH/nu-test5.txt"); DefaultHttpClient httpclient = new DefaultHttpClient(); UsernamePasswordCredentials upc = new UsernamePasswordCredentials("[email protected]", ""); HttpPost httppost = new HttpPost("http://api.localhostr.com/file"); try { httppost.addHeader(new BasicScheme().authenticate(upc, httppost)); } catch (AuthenticationException ex) { Logger.getLogger(LocalhostrUploaderPlugin.class.getName()).log(Level.SEVERE, null, ex); } MultipartEntity mpEntity = new MultipartEntity(); ContentBody cbFile = new FileBody(file); mpEntity.addPart("name", new StringBody(file.getName())); mpEntity.addPart("file", cbFile); httppost.setEntity(mpEntity); System.out.println("Now uploading your file into localhost..........................."); HttpResponse response = httpclient.execute(httppost); HttpEntity resEntity = response.getEntity(); System.out.println(response.getStatusLine()); if (resEntity != null) { String tmp = EntityUtils.toString(resEntity); System.out.println(tmp); downloadlink = tmp.substring(tmp.indexOf("http:")); downloadlink = downloadlink.substring(0, downloadlink.indexOf("\"")); System.out.println("download link : " + downloadlink); } // uploadresponse = response.getLastHeader("Location").getValue(); // System.out.println("Upload response : " + uploadresponse); }
Example #24
Source File: OronUploaderPlugin.java From neembuu-uploader with GNU General Public License v3.0 | 5 votes |
public static void fileUpload() throws IOException { HttpClient httpclient = new DefaultHttpClient(); httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); file = new File("H:\\Dinesh.java"); HttpPost httppost = new HttpPost(oronlink); if (login) { httppost.setHeader("Cookie", logincookie + ";" + xfsscookie); } MultipartEntity mpEntity = new MultipartEntity(); ContentBody cbFile = new FileBody(file); mpEntity.addPart("upload_type", new StringBody("file")); mpEntity.addPart("srv_id", new StringBody(serverID)); if (login) { mpEntity.addPart("sess_id", new StringBody(xfsscookie.substring(5))); } mpEntity.addPart("srv_tmp_url", new StringBody(tmpserver)); mpEntity.addPart("file_0", cbFile); httppost.setEntity(mpEntity); System.out.println("Now uploading your file into oron..........................."); HttpResponse response = httpclient.execute(httppost); HttpEntity resEntity = response.getEntity(); System.out.println(response.getStatusLine()); if (resEntity != null) { String tmp = EntityUtils.toString(resEntity); System.out.println("Upload response : " + tmp); fnvalue = parseResponse(tmp, "name='fn' value='", "'"); System.out.println("fn value : " + fnvalue); } // uploadresponse = response.getLastHeader("Location").getValue(); // System.out.println("Upload response : " + uploadresponse); }
Example #25
Source File: GigaSizeUploaderPlugin.java From neembuu-uploader with GNU General Public License v3.0 | 5 votes |
public static void fileUpload() throws IOException { HttpClient httpclient = new DefaultHttpClient(); httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); file = new File("/media/backup/Projects/NU/NeembuuUploader/test/neembuuuploader/test/plugins/RapidShareUploaderPlugin.java"); // file = new File("e:\\dinesh.txt"); HttpPost httppost = new HttpPost("http://www.gigasize.com/uploadie"); httppost.setHeader("Cookie", cookies.toString()); MultipartEntity mpEntity = new MultipartEntity(); ContentBody cbFile = new FileBody(file); mpEntity.addPart("UPLOAD_IDENTIFIER", new StringBody(uploadid)); mpEntity.addPart("sid", new StringBody(sid)); mpEntity.addPart("fileUpload1", cbFile); httppost.setEntity(mpEntity); System.out.println("Now uploading your file into Gigasize..........................."); System.out.println("Now executing......." + httppost.getRequestLine()); HttpResponse response = httpclient.execute(httppost); HttpEntity resEntity = response.getEntity(); System.out.println(response.getStatusLine()); if (resEntity != null) { sid = ""; sid = EntityUtils.toString(resEntity); System.out.println("After upload sid value : " + sid); } // uploadresponse = response.getLastHeader("Location").getValue(); // System.out.println("Upload response : " + uploadresponse); }
Example #26
Source File: BadongoUploaderPlugin.java From neembuu-uploader with GNU General Public License v3.0 | 5 votes |
private static void fileUpload() throws IOException { HttpClient httpclient = new DefaultHttpClient(); if (login) { postURL = "http://upload.badongo.com/mpu_upload.php"; } HttpPost httppost = new HttpPost(postURL); file = new File("g:/S2SClient.7z"); MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); ContentBody cbFile = new FileBody(file); mpEntity.addPart("Filename", new StringBody(file.getName())); if (login) { mpEntity.addPart("PHPSESSID", new StringBody(dataid)); } mpEntity.addPart("Filedata", cbFile); httppost.setEntity(mpEntity); System.out.println("executing request " + httppost.getRequestLine()); System.out.println("Now uploading your file into badongo.com"); HttpResponse response = httpclient.execute(httppost); HttpEntity resEntity = response.getEntity(); // uploadresponse = response.getLastHeader("Location").getValue(); System.out.println("Upload response : " + uploadresponse); System.out.println(response.getStatusLine()); if (resEntity != null) { uploadresponse = EntityUtils.toString(resEntity); } // if (resEntity != null) { // resEntity.consumeContent(); // } System.out.println("res " + uploadresponse); httpclient.getConnectionManager().shutdown(); }
Example #27
Source File: FileUploadDownloadClient.java From incubator-pinot with Apache License 2.0 | 5 votes |
private static HttpUriRequest getDeleteFileRequest(String method, URI uri, ContentBody contentBody, @Nullable List<Header> headers, @Nullable List<NameValuePair> parameters, int socketTimeoutMs) { // Build the Http entity HttpEntity entity = MultipartEntityBuilder.create().setMode(HttpMultipartMode.BROWSER_COMPATIBLE) .addPart(contentBody.getFilename(), contentBody).build(); // Build the request RequestBuilder requestBuilder = RequestBuilder.create(method).setVersion(HttpVersion.HTTP_1_1).setUri(uri).setEntity(entity); addHeadersAndParameters(requestBuilder, headers, parameters); setTimeout(requestBuilder, socketTimeoutMs); return requestBuilder.build(); }
Example #28
Source File: HttpClientWrapper.java From TrackRay with GNU General Public License v3.0 | 5 votes |
/** * POST方式发送名值对请求URL,上传文件(包括图片) * * @param url * @return * @throws HttpException * @throws IOException */ public ResponseStatus postEntity(String url, String urlEncoding) throws HttpException, IOException { if (url == null) return null; HttpEntity entity = null; HttpRequestBase request = null; CloseableHttpResponse response = null; try { this.parseUrl(url); HttpPost httpPost = new HttpPost(toUrl()); //对请求的表单域进行填充 MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create(); entityBuilder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); for (NameValuePair nameValuePair : this.getNVBodies()) { entityBuilder.addPart(nameValuePair.getName(), new StringBody(nameValuePair.getValue(), ContentType.create("text/plain", urlEncoding))); } for (ContentBody contentBody : getContentBodies()) { entityBuilder.addPart("file", contentBody); } entityBuilder.setCharset(CharsetUtils.get(urlEncoding)); httpPost.setEntity(entityBuilder.build()); request = httpPost; response = client.execute(request); //响应状态 StatusLine statusLine = response.getStatusLine(); // 获取响应对象 entity = response.getEntity(); ResponseStatus ret = new ResponseStatus(); ret.setStatusCode(statusLine.getStatusCode()); getResponseStatus(entity, ret); return ret; } finally { close(entity, request, response); } }
Example #29
Source File: RapidShareUploaderPlugin.java From neembuu-uploader with GNU General Public License v3.0 | 5 votes |
public static void fileUpload() throws IOException { HttpClient httpclient = new DefaultHttpClient(); httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); file = new File("/home/vigneshwaran/VIGNESH/dinesh.txt"); HttpPost httppost = new HttpPost(postURL); //httppost.setHeader("Cookie", usercookie); MultipartEntity mpEntity = new MultipartEntity(); ContentBody cbFile = new FileBody(file); mpEntity.addPart("sub", new StringBody("upload")); mpEntity.addPart("cookie", new StringBody(cookie)); mpEntity.addPart("folder", new StringBody("0")); mpEntity.addPart("filecontent", cbFile); httppost.setEntity(mpEntity); System.out.println("Now uploading your file into rs..........................."); HttpResponse response = httpclient.execute(httppost); HttpEntity resEntity = response.getEntity(); System.out.println(response.getStatusLine()); if (resEntity != null) { uploadresponse = EntityUtils.toString(resEntity); System.out.println("Actual response : " + uploadresponse); uploadresponse = uploadresponse.replace("COMPLETE\n", ""); // downloadid=uploadresponse.substring(uploadresponse.indexOf("E")+1); downloadid = uploadresponse.substring(0, uploadresponse.indexOf(",")); uploadresponse = uploadresponse.replace(downloadid + ",", ""); filename = uploadresponse.substring(0, uploadresponse.indexOf(",")); System.out.println("download id : " + downloadid); // filename=uploadresponse.substring(uploadresponse.indexOf(",")); // filename=uploadresponse.substring(0, uploadresponse.indexOf(",")); System.out.println("File name : " + filename); downloadlink = "http://rapidshare.com/files/" + downloadid + "/" + filename; System.out.println("Download Link :" + downloadlink); } }
Example #30
Source File: MegaUploadUploaderPlugin.java From neembuu-uploader with GNU General Public License v3.0 | 5 votes |
public static void fileUpload() throws IOException { HttpClient httpclient = new DefaultHttpClient(); httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); file = new File("H:\\c programs.doc"); filelength = file.length(); if (!username.isEmpty() && !password.isEmpty()) { postURL = megauploadlink + "upload_done.php?UPLOAD_IDENTIFIER=" + uploadID + "&user=undefined&s=" + filelength; } else { postURL = megauploadlink + "upload_done.php?UPLOAD_IDENTIFIER=" + uploadID + "&" + usercookie + "&s=" + filelength; } HttpPost httppost = new HttpPost(postURL); httppost.setHeader("Cookie", usercookie); MultipartEntity mpEntity = new MultipartEntity(); ContentBody cbFile = new FileBody(file); mpEntity.addPart("", cbFile); httppost.setEntity(mpEntity); System.out.println("Now uploading your file into megaupload..........................."); HttpResponse response = httpclient.execute(httppost); HttpEntity resEntity = response.getEntity(); System.out.println(response.getStatusLine()); if (resEntity != null) { downloadlink = EntityUtils.toString(resEntity); } }