Package org.apache.http.entity

Examples of org.apache.http.entity.FileEntity


        if(!hasArguments() && getSendFileAsPostBody()) {
            hasEntityBody = true;

            // If getSendFileAsPostBody returned true, it's sure that file is not null
            FileEntity fileRequestEntity = new FileEntity(new File(files[0].getPath())); // no need for content-type here
            entity.setEntity(fileRequestEntity);
        }
        // If none of the arguments have a name specified, we
        // just send all the values as the entity body
        else if(getSendParameterValuesAsPostBody()) {
View Full Code Here


                    else {
                        post.setHeader(HEADER_CONTENT_TYPE, APPLICATION_X_WWW_FORM_URLENCODED);
                    }
                }

                FileEntity fileRequestEntity = new FileEntity(new File(file.getPath()),(String) null);// TODO is null correct?
                post.setEntity(fileRequestEntity);

                // We just add placeholder text for file content
                postedBody.append("<actual file content, not shown here>");
            } else {
View Full Code Here

        if(!hasArguments() && getSendFileAsPostBody()) {
            hasPutBody = true;

            // If getSendFileAsPostBody returned true, it's sure that file is not null
            FileEntity fileRequestEntity = new FileEntity(new File(files[0].getPath()), (String) null); // TODO is null correct?
            put.setEntity(fileRequestEntity);

            // We just add placeholder text for file content
            putBody.append("<actual file content, not shown here>");
        }
View Full Code Here

                        answer = entity;
                    } else if (data instanceof File || data instanceof GenericFile) {
                        // file based (could potentially also be a FTP file etc)
                        File file = in.getBody(File.class);
                        if (file != null) {
                            answer = new FileEntity(file, contentType);
                        }
                    } else if (data instanceof String) {
                        // be a bit careful with String as any type can most likely be converted to String
                        // so we only do an instanceof check and accept String if the body is really a String
                        // do not fallback to use the default charset as it can influence the request
View Full Code Here

        HttpPost post = new HttpPost(providerURI);
        post.addHeader("Content-Type", "image/gif");
        post.addHeader("Title", "Title " + receiptName + "");
        post.addHeader("Slug", "Slug " + receiptName + "");

        post.setEntity(new FileEntity(input, "image/gif"));

        // Get HTTP client
        org.apache.http.client.HttpClient httpclient = new HttpClientFactory().createHttpClient();
        try {
            // Execute request
View Full Code Here

        // ...binary data...
        HttpPut put = new HttpPut(providerURI + "/" + mediaId);
        put.addHeader("Content-Type", "image/jpg");
        put.addHeader("Title", "Title " + receiptName + "");
        put.addHeader("Slug", "Slug " + receiptName + "");
        put.setEntity(new FileEntity(input, "image/jpg"));

        // Get HTTP client
        HttpClient httpclient = new HttpClientFactory().createHttpClient();
        try {
            // Execute request
View Full Code Here

        // ...binary data...
        HttpPut put = new HttpPut(providerURI + "/" + mediaId + "-bogus"); // Does not exist.
        put.addHeader("Content-Type", "image/jpg");
        put.addHeader("Title", "Title " + receiptName + "");
        put.addHeader("Slug", "Slug " + receiptName + "");
        put.setEntity(new FileEntity(input, "image/jpg"));

        // Get HTTP client
        HttpClient httpclient = new HttpClientFactory().createHttpClient();
        try {
            // Execute request
View Full Code Here

            }
            String contenttype = null;
            if (cmd.hasOption('T')) {
                contenttype = cmd.getOptionValue('T');
            }
            FileEntity entity = new FileEntity(file, contenttype);
            if (file.length() > 100000) {
                entity.setChunked(true);
            }
            HttpPost httppost = new HttpPost(url.getPath());
            httppost.setEntity(entity);
            request = httppost;
        } else if (cmd.hasOption('i')) {
View Full Code Here

        HttpEntity entity = null;

        // Prepare requests for each thread
        if (config.getPayloadFile() != null) {
            entity = new FileEntity(config.getPayloadFile(), config.getContentType());
            ((FileEntity) entity).setChunked(config.isUseChunking());
            contentLength = config.getPayloadFile().length();

        } else if (config.getPayloadText() != null) {
            entity = new StringEntity(config.getPayloadText(), config.getContentType(), "UTF-8");
View Full Code Here

                body.setContentType("text/html; charset=UTF-8");
                response.setEntity(body);
                log.error("无法读取文件" + file.getPath(), true);
            } else {
                response.setStatusCode(HttpStatus.SC_OK);
                FileEntity body = new FileEntity(file, "text/html");
                response.setEntity(body);
                log.info("发送文件" + file.getPath(), true);
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.http.entity.FileEntity

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.