当前位置: 首页>>代码示例>>Java>>正文


Java FileBody类代码示例

本文整理汇总了Java中org.apache.http.entity.mime.content.FileBody的典型用法代码示例。如果您正苦于以下问题:Java FileBody类的具体用法?Java FileBody怎么用?Java FileBody使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FileBody类属于org.apache.http.entity.mime.content包,在下文中一共展示了FileBody类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fileUpload

import org.apache.http.entity.mime.content.FileBody; //导入依赖的package包/类
private static void fileUpload() throws Exception {

        file = new File("/home/vigneshwaran/VIGNESH/dinesh.txt");
        httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(postURL);


        MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
        ContentBody cbFile = new FileBody(file);
        mpEntity.addPart("Filename", new StringBody(file.getName()));
        mpEntity.addPart("ssd", new StringBody(ssd));
        mpEntity.addPart("Filedata", cbFile);
        httppost.setEntity(mpEntity);
        System.out.println("executing request " + httppost.getRequestLine());
        System.out.println("Now uploading your file into slingfile.com");
        HttpResponse response = httpclient.execute(httppost);
//        HttpEntity resEntity = response.getEntity();
        System.out.println(response.getStatusLine());
        System.out.println(EntityUtils.toString(response.getEntity())); 

    }
 
开发者ID:Neembuu-Uploader,项目名称:neembuu-uploader,代码行数:22,代码来源:SlingFileUploaderPlugin.java

示例2: testFormParamWithFile

import org.apache.http.entity.mime.content.FileBody; //导入依赖的package包/类
@Test
public void testFormParamWithFile() throws IOException, URISyntaxException {
    HttpURLConnection connection = request("/test/v1/testFormParamWithFile", HttpMethod.POST);
    File file = new File(Thread.currentThread().getContextClassLoader().getResource("testJpgFile.jpg").toURI());
    MultipartEntityBuilder builder = MultipartEntityBuilder.create();
    FileBody fileBody = new FileBody(file, ContentType.DEFAULT_BINARY);
    builder.addPart("form", fileBody);
    HttpEntity build = builder.build();
    connection.setRequestProperty("Content-Type", build.getContentType().getValue());
    try (OutputStream out = connection.getOutputStream()) {
        build.writeTo(out);
    }

    InputStream inputStream = connection.getInputStream();
    String response = StreamUtil.asString(inputStream);
    IOUtils.closeQuietly(inputStream);
    connection.disconnect();
    assertEquals(response, file.getName());
}
 
开发者ID:wso2,项目名称:msf4j,代码行数:20,代码来源:HttpServerTest.java

示例3: testSingleFileUpload

import org.apache.http.entity.mime.content.FileBody; //导入依赖的package包/类
@Test
public void testSingleFileUpload() throws IOException {
	// given
	File file = new File(UUID.randomUUID().toString());
	InputStream attachment = Resources.getResource("attachment.txt").openStream();		
	FileUtils.copyInputStreamToFile(attachment, file);
	
	// when
	WebResponse response = WebRequest.post("/singlefile")
			.withFileBody("file", new FileBody(file))
			.execute();

	// then
	assertThat(response, not(nullValue()));
	assertThat(response.getStatusCode(), equalTo(StatusCodes.OK));
	assertThat(response.getContent(), equalTo("This is an attachment"));
	file.delete();
}
 
开发者ID:svenkubiak,项目名称:mangooio,代码行数:19,代码来源:FormControllerTest.java

示例4: testMultiFileUpload

import org.apache.http.entity.mime.content.FileBody; //导入依赖的package包/类
@Test
public void testMultiFileUpload() throws IOException {
	// given
	File file1 = new File(UUID.randomUUID().toString());
	File file2 = new File(UUID.randomUUID().toString());
	InputStream attachment1 = Resources.getResource("attachment.txt").openStream();
	InputStream attachment2 = Resources.getResource("attachment.txt").openStream();
	FileUtils.copyInputStreamToFile(attachment1, file1);
	FileUtils.copyInputStreamToFile(attachment2, file2);
	
	// when
	WebResponse response = WebRequest.post("/multifile")
			.withFileBody("file1", new FileBody(file1))
			.withFileBody("file2", new FileBody(file2))
			.execute();

	// then
	assertThat(response, not(nullValue()));
	assertThat(response.getStatusCode(), equalTo(StatusCodes.OK));
	assertThat(response.getContent(), equalTo("This is an attachmentThis is an attachment2"));
	file1.delete();
	file2.delete();
}
 
开发者ID:svenkubiak,项目名称:mangooio,代码行数:24,代码来源:FormControllerTest.java

示例5: fileUpload

import org.apache.http.entity.mime.content.FileBody; //导入依赖的package包/类
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();
}
 
开发者ID:Neembuu-Uploader,项目名称:neembuu-uploader,代码行数:27,代码来源:ZippyShareUploaderPlugin.java

示例6: fileUpload

import org.apache.http.entity.mime.content.FileBody; //导入依赖的package包/类
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();
}
 
开发者ID:Neembuu-Uploader,项目名称:neembuu-uploader,代码行数:21,代码来源:MegaShareUploaderPlugin.java

示例7: fileUpload

import org.apache.http.entity.mime.content.FileBody; //导入依赖的package包/类
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);
    }
}
 
开发者ID:Neembuu-Uploader,项目名称:neembuu-uploader,代码行数:24,代码来源:MediaFireUploadPlugin.java

示例8: fileUpload

import org.apache.http.entity.mime.content.FileBody; //导入依赖的package包/类
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();
}
 
开发者ID:Neembuu-Uploader,项目名称:neembuu-uploader,代码行数:23,代码来源:ShareSendUploaderPlugin.java

示例9: fileUpload

import org.apache.http.entity.mime.content.FileBody; //导入依赖的package包/类
public static void fileUpload() throws Exception {
        DefaultHttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(postURL);
        MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
        //reqEntity.addPart("string_field",new StringBody("field value"));
        FileBody bin = new FileBody(new File("/home/vigneshwaran/VIGNESH/naruto.txt"));
        reqEntity.addPart("fff", bin);
        httppost.setEntity(reqEntity);
        System.out.println("Now uploading your file into 2shared.com. Please wait......................");
        HttpResponse response = httpclient.execute(httppost);
//        HttpEntity resEntity = response.getEntity();
//
//        if (resEntity != null) {
//            String page = EntityUtils.toString(resEntity);
//            System.out.println("PAGE :" + page);
//        }
    }
 
开发者ID:Neembuu-Uploader,项目名称:neembuu-uploader,代码行数:18,代码来源:TwoSharedUploaderPlugin.java

示例10: fileUpload

import org.apache.http.entity.mime.content.FileBody; //导入依赖的package包/类
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);
    }
 
开发者ID:Neembuu-Uploader,项目名称:neembuu-uploader,代码行数:23,代码来源:UploadBoxUploaderPlugin.java

示例11: fileUpload

import org.apache.http.entity.mime.content.FileBody; //导入依赖的package包/类
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 :(");
    }

}
 
开发者ID:Neembuu-Uploader,项目名称:neembuu-uploader,代码行数:24,代码来源:WuploadUploaderPlugin.java

示例12: fileUpload

import org.apache.http.entity.mime.content.FileBody; //导入依赖的package包/类
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));

    }
 
开发者ID:Neembuu-Uploader,项目名称:neembuu-uploader,代码行数:23,代码来源:DivShareUploaderPlugin.java

示例13: fileUpload

import org.apache.http.entity.mime.content.FileBody; //导入依赖的package包/类
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);
    }
 
开发者ID:Neembuu-Uploader,项目名称:neembuu-uploader,代码行数:27,代码来源:UGotFileUploaderPlugin.java

示例14: fileUpload

import org.apache.http.entity.mime.content.FileBody; //导入依赖的package包/类
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);
    }
 
开发者ID:Neembuu-Uploader,项目名称:neembuu-uploader,代码行数:26,代码来源:ZohoDocsUploaderPlugin.java

示例15: convertFromFileToFile

import org.apache.http.entity.mime.content.FileBody; //导入依赖的package包/类
/**
 * Handles conversion from file to file with given File object
 * @param dest The output file object
 * @return True on success, false on error
 * @throws IOException 
 */
private boolean convertFromFileToFile(File dest) throws IOException {
    if (!this.getInputFile().exists()) {
        throw new IllegalArgumentException("MsWordToImageConvert: Input file was not found at '" + this.input.getValue() + "'");
    }

    HttpClient client = HttpClientBuilder.create().build();
    HttpPost post = new HttpPost(this.constructMsWordToImageAddress(new HashMap<>()));
    MultipartEntityBuilder builder = MultipartEntityBuilder.create();
    builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
    builder.addPart("file_contents", new FileBody(this.getInputFile()));
    post.setEntity(builder.build());
    
    HttpResponse response = client.execute(post);

    HttpEntity entity = response.getEntity();
    try (FileOutputStream fileOS = new FileOutputStream(dest)) {
        entity.writeTo(fileOS);
        fileOS.flush();
    }
    return true;
}
 
开发者ID:msword2image,项目名称:msword2image-java,代码行数:28,代码来源:MsWordToImageConvert.java


注:本文中的org.apache.http.entity.mime.content.FileBody类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。