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


Java MultipartEntityBuilder.addBinaryBody方法代码示例

本文整理汇总了Java中org.apache.http.entity.mime.MultipartEntityBuilder.addBinaryBody方法的典型用法代码示例。如果您正苦于以下问题:Java MultipartEntityBuilder.addBinaryBody方法的具体用法?Java MultipartEntityBuilder.addBinaryBody怎么用?Java MultipartEntityBuilder.addBinaryBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.http.entity.mime.MultipartEntityBuilder的用法示例。


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

示例1: addTpl

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
/**
 * 
 * @param param
 *            apikey sign
 * @param layout
 *            {@code VideoLayout}
 * @param material
 *            视频资料zip文件
 * 
 * @return
 */
public Result<Template> addTpl(Map<String, String> param, String layout, byte[] material) {
    Result<Template> r = new Result<>();
    if (layout == null || material == null) return r.setCode(Code.ARGUMENT_MISSING);
    List<NameValuePair> list = param2pair(param, r, APIKEY, SIGN);
    if (r.getCode() != Code.OK) return r;

    Charset ch = Charset.forName(charset());
    MultipartEntityBuilder builder = MultipartEntityBuilder.create().setCharset(ch).setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
    for (NameValuePair pair : list) {
        builder.addTextBody(pair.getName(), pair.getValue(), ContentType.create("text/plain", ch));
    }
    builder.addTextBody(LAYOUT, layout, ContentType.APPLICATION_JSON);
    builder.addBinaryBody(MATERIAL, material, ContentType.create("application/octet-stream", ch), null);

    StdResultHandler<Template> h = new StdResultHandler<>();
    try {
        return path("add_tpl.json").post(new HttpEntityWrapper(builder.build()), h, r);
    } catch (Exception e) {
        return h.catchExceptoin(e, r);
    }
}
 
开发者ID:yunpian,项目名称:yunpian-java-sdk,代码行数:33,代码来源:VideoSmsApi.java

示例2: getHttpEntity

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
@Override
public HttpEntity getHttpEntity() {
  MultipartEntityBuilder builder = MultipartEntityBuilder.create();

  if (url != null)
    builder.addTextBody(URL_FIELD, url);

  if (certificate != null)
    builder.addBinaryBody(CERTIFICATE_FIELD, new File(certificate));

  if (maxConnections != null)
    builder.addTextBody(MAX_CONNECTIONS_FIELD, maxConnections.toString());

  if (allowedUpdates != null) {
    if (allowedUpdates.length == 0) {
      builder.addTextBody(ALLOWED_UPDATES_FIELD, "[]");
    } else {
      for (String allowedUpdate : allowedUpdates) {
        builder.addTextBody(ALLOWED_UPDATES_FIELD + "[]", allowedUpdate);
      }
    }
  }

  return builder.build();
}
 
开发者ID:AgeOfWar,项目名称:Telejam,代码行数:26,代码来源:SetWebhook.java

示例3: addBody

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
@SneakyThrows
protected void addBody(MultipartEntityBuilder request, VxmlRequestTask task) {

	super.addBody(request, task);

	String id = task.getKey();
	if (task.getUtterances().isEmpty()) {
		task.addUtterance(String.format("%s/%s-2-%s-1.wav", id, id, parameters.getPrintName()));
	}
	File utterance = task.getUtterances().get(0);

	byte[] byteArray = IOUtils.toByteArray(new FileInputStream(utterance));
	request.addBinaryBody(REQ_UTTERANCE, byteArray);

	if (task.isFeatureVector()) {
		request.addTextBody(REQ_FEATURE_VECTOR, "true");
	}

	if (parameters.isTextPrompted()) {
		request.addTextBody(REQ_VOCAB, parameters.getVocab());
		String fileName = FilenameUtils.removeExtension(utterance.getPath());
		request.addTextBody(REQ_PHRASE, FileUtils.readFileToString(new File(String.format("%s.txt", fileName)), "UTF-8").trim());
	}

	summary.getByteCount().add(byteArray.length);
}
 
开发者ID:Auraya,项目名称:armorvox-client,代码行数:27,代码来源:VxmlClientVerify.java

示例4: main

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
public static void main(String args[]){
    HttpClient httpClient = HttpClients.createDefault();
    HttpPost httpPost = new HttpPost("http://localhost:8080/sso-web/upload");
    httpPost.addHeader("Range","bytes=10000-");
    final MultipartEntityBuilder multipartEntity = MultipartEntityBuilder.create();
    multipartEntity.setCharset(Consts.UTF_8);
    multipartEntity.setMode(HttpMultipartMode.STRICT);
    multipartEntity.addBinaryBody("file", new File("/Users/huanghuanlai/Desktop/test.java"));
    httpPost.setEntity(multipartEntity.build());
    try {
        HttpResponse response = httpClient.execute(httpPost);

    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:dounine,项目名称:clouddisk,代码行数:17,代码来源:ClassTest.java

示例5: initRequest

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
public HttpPost initRequest(final FileUploadParameter parameter) {
	final FileUploadAddress fileUploadAddress = getDependResult(FileUploadAddress.class);
	final HttpPost request = new HttpPost("http://" + fileUploadAddress.getData().getUp() + CONST.URI_PATH);
	final MultipartEntityBuilder multipartEntity = MultipartEntityBuilder.create();
	multipartEntity.setCharset(Consts.UTF_8);
	multipartEntity.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
	multipartEntity.addPart(CONST.QID_NAME, new StringBody(getLoginInfo().getQid(), ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("ofmt", new StringBody("json", ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("method", new StringBody("Upload.web", ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("token", new StringBody(readCookieStoreValue("token"), ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("v", new StringBody("1.0.1", ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("tk", new StringBody(fileUploadAddress.getData().getTk(), ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("Upload", new StringBody("Submit Query", ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("devtype", new StringBody("web", ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("pid", new StringBody("ajax", ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("Filename",
			new StringBody(parameter.getUploadFile().getName(), ContentType.APPLICATION_JSON));
	multipartEntity.addPart("path", new StringBody(parameter.getPath(), ContentType.APPLICATION_JSON));// 解决中文不识别问题
	multipartEntity.addBinaryBody("file", parameter.getUploadFile());
	request.setEntity(multipartEntity.build());
	return request;
}
 
开发者ID:dounine,项目名称:clouddisk,代码行数:23,代码来源:FileUploadParser.java

示例6: PostData

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
static void PostData() throws Exception {
	final String url = "https://upload.gyazo.com/api/upload";
	final HttpClient httpclient = new Downloader().client;

	// create the post request.
	final HttpPost httppost = new HttpPost(url);
	final MultipartEntityBuilder builder = MultipartEntityBuilder.create();

	final File f = new File("./src/main/resources/assets/signpic/textures/logo.png");
	builder.addBinaryBody("imagedata", f, ContentType.DEFAULT_BINARY, f.getName());
	builder.addTextBody("access_token", "4d080e95be741beba0b74653a872668326a79526784d2daed9190dc584bffad7");
	httppost.setEntity(builder.build());

	// execute request
	final HttpResponse response = httpclient.execute(httppost);
	final HttpEntity resEntity = response.getEntity();
	final InputStream stream = resEntity.getContent();

	System.out.println(response.getStatusLine());
	System.out.println(convertStreamToString(stream));

}
 
开发者ID:Team-Fruit,项目名称:SignPicture,代码行数:23,代码来源:Debug.java

示例7: post

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
public Response post(String url, String auth, JsonJavaObject postData, File fileUpload) throws JsonException, IOException, URISyntaxException {
	URI normUri = new URI(url).normalize();
	Request postRequest = Request.Post(normUri);
	
	//Add all headers
	if(StringUtil.isNotEmpty(auth)) {
		postRequest.addHeader("Authorization", auth);
	}
	
	MultipartEntityBuilder builder = MultipartEntityBuilder.create();
	builder.addBinaryBody("images_file", fileUpload, ContentType.APPLICATION_OCTET_STREAM, fileUpload.getName());
	
	if(postData != null) {
		String postDataString = JsonGenerator.toJson(JsonJavaFactory.instanceEx, postData);
		builder.addTextBody("classifier_ids", postDataString, ContentType.MULTIPART_FORM_DATA);
	}
	
	HttpEntity multipart = builder.build();
	postRequest.body(multipart);
	
	Response response = executor.execute(postRequest);
	return response;
}
 
开发者ID:OpenNTF,项目名称:XPages-Fusion-Application,代码行数:24,代码来源:RestUtil.java

示例8: setMultipartFileData

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
/**
 * This will take a list of files, and attach them to the 
 * MultipartEntityBuilder instance
 * @param files Files to add
 * @param builder builder 
 */
private void setMultipartFileData( final Map<String,PostFile> files, 
  final MultipartEntityBuilder builder )
{
  //..Check for input files
  if ( files == null || builder == null )
    return;    
  
  for ( final String name : files.keySet())
  {
    //..Ensure the file exists
    final PostFile pf = files.get( name );

    if ( !pf.getFile().exists())
    {
      throw new IllegalArgumentException( 
        pf.getFile() + " (" + pf.getFilename() 
          + ") does not exist; cannot upload non-existent file." );
    }

    APILog.trace( LOG, "Added file", pf.getFile(), "(", pf.getFilename(), ")" );

    builder.addBinaryBody( name, pf.getFile(), pf.getContentType(), pf.getFilename());
  }
}
 
开发者ID:SixArmDonkey,项目名称:aerodrome-for-jet,代码行数:31,代码来源:API.java

示例9: addStreamToEntity

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
/**
 * Adds a stream to an HTTP entity
 *
 * @param someStream Input stream to be added to an HTTP entity
 * @param fieldName A description of the entity content
 * @param fileName Name of the file attached as an entity
 * @return HTTP entity
 * @throws IOException Signals a failure while reading the input stream
 */
HttpEntity addStreamToEntity(InputStream someStream, String fieldName, String fileName) throws IOException {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    int bytesRead;
    byte[] bytes = new byte[1024];
    while ((bytesRead = someStream.read(bytes)) > 0) {
        byteArrayOutputStream.write(bytes, 0, bytesRead);
    }
    byte[] data = byteArrayOutputStream.toByteArray();

    MultipartEntityBuilder builder = MultipartEntityBuilder.create();
    builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
    builder.setStrictMode();
    builder.addBinaryBody(fieldName, data, ContentType.MULTIPART_FORM_DATA, fileName);
    return builder.build();
}
 
开发者ID:Microsoft,项目名称:Cognitive-SpeakerRecognition-Android,代码行数:25,代码来源:SpeakerRestClientHelper.java

示例10: deployBPMNPackage

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
/**
 * This Method is used to deploy BPMN packages to the BPMN Server
 *
 * @param fileName The name of the Package to be deployed
 * @param filePath The location of the BPMN package to be deployed
 * @throws java.io.IOException
 * @throws org.json.JSONException
 * @returns String array with status, deploymentID and Name
 */
public String[] deployBPMNPackage(String filePath, String fileName)
        throws RestClientException, IOException, JSONException {
    String url = serviceURL + "repository/deployments";
    DefaultHttpClient httpClient = getHttpClient();
    HttpPost httpPost = new HttpPost(url);
    MultipartEntityBuilder builder = MultipartEntityBuilder.create();
    builder.addBinaryBody("file", new File(filePath),
                          ContentType.MULTIPART_FORM_DATA, fileName);
    HttpEntity multipart = builder.build();
    httpPost.setEntity(multipart);
    HttpResponse response = httpClient.execute(httpPost);
    String status = response.getStatusLine().toString();
    String responseData = EntityUtils.toString(response.getEntity());
    JSONObject jsonResponseObject = new JSONObject(responseData);
    if (status.contains(Integer.toString(HttpStatus.SC_CREATED)) || status.contains(Integer.toString(HttpStatus.SC_OK))) {
        String deploymentID = jsonResponseObject.getString(ID);
        String name = jsonResponseObject.getString(NAME);
        return new String[]{status, deploymentID, name};
    } else if (status.contains(Integer.toString(HttpStatus.SC_INTERNAL_SERVER_ERROR))) {
        String errorMessage = jsonResponseObject.getString("errorMessage");
        throw new RestClientException(errorMessage);
    } else {
        throw new RestClientException("Failed to deploy package " + fileName);
    }
}
 
开发者ID:wso2,项目名称:product-ei,代码行数:35,代码来源:ActivitiRestClient.java

示例11: createMultipartEntity

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
/**
 * Creates required multipart entity with the image binary
 * 
 * @return HttpEntity to send on the post
 * @throws ClientProtocolException
 * @throws IOException
 */
protected HttpEntity createMultipartEntity() throws ClientProtocolException, IOException {
    MultipartEntityBuilder builder = MultipartEntityBuilder.create();
    builder.addBinaryBody("file", file);

    HttpEntity entity = builder.build();
    return entity;
}
 
开发者ID:brunocvcunha,项目名称:jiphy,代码行数:15,代码来源:JiphyUploadRequest.java

示例12: ClientConnection

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
/**
 * POST request
 * @param urlstring
 * @param map
 * @param useAuthentication
 * @throws ClientProtocolException 
 * @throws IOException
 */
public ClientConnection(String urlstring, Map<String, byte[]> map, boolean useAuthentication) throws ClientProtocolException, IOException {
    this.request = new HttpPost(urlstring);        
    MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();
    entityBuilder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
    for (Map.Entry<String, byte[]> entry: map.entrySet()) {
        entityBuilder.addBinaryBody(entry.getKey(), entry.getValue());
    }
    ((HttpPost) this.request).setEntity(entityBuilder.build());
    this.request.setHeader("User-Agent", ClientIdentification.getAgent(ClientIdentification.yacyInternetCrawlerAgentName).userAgent);
    this.init();
}
 
开发者ID:yacy,项目名称:yacy_grid_mcp,代码行数:20,代码来源:ClientConnection.java

示例13: executeHttpPost

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
/**
 * Performs HTTP Post request with OAuth authentication for the endpoint
 * with the given path, with the given binary bodies as payload. Uses
 * multipart/mixed content type.
 * 
 * @param path
 *            the path to be called.
 * @param binaryBodies
 *            the payload.
 * @return the CloseableHttpResponse object.
 * @throws ClientProtocolException
 * @throws IOException
 */
CloseableHttpResponse executeHttpPost(String path, List<BinaryBody> binaryBodies)
		throws ClientProtocolException, IOException {
	logger.debug(DEBUG_EXECUTING_HTTP_POST_FOR_WITH_BINARY_BODIES, baseUri, path);

	HttpPost httpPost = createHttpPost(baseUri + path);
	httpPost.setHeader(HttpHeaders.CONTENT_TYPE, MULTIPART_MIXED_BOUNDARY);

	MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create();

	for (BinaryBody binaryBody : binaryBodies) {
		multipartEntityBuilder.addBinaryBody(binaryBody.getBinaryBodyName(), binaryBody.getFileStream(),
				ContentType.create(binaryBody.getMediaType()), binaryBody.getFileName());
	}

	HttpEntity httpEntity = multipartEntityBuilder.setBoundary(OpenApisEndpoint.BOUNDARY).build();
	httpPost.setEntity(httpEntity);

	CloseableHttpClient httpClient = HttpClients.createDefault();
	CloseableHttpResponse response = httpClient.execute(httpPost);

	logger.debug(DEBUG_EXECUTED_HTTP_POST_FOR_WITH_BINARY_BODIES, baseUri, path);
	return response;
}
 
开发者ID:SAP,项目名称:cloud-ariba-partner-flow-extension-ext,代码行数:37,代码来源:OpenApisEndpoint.java

示例14: getHttpEntity

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
@Override
public HttpEntity getHttpEntity() {
  MultipartEntityBuilder builder = MultipartEntityBuilder.create();
  
  if (chatId != null)
    builder.addTextBody(CHAT_ID_FIELD, chatId);
  
  if (media != null) {
    builder.addTextBody(MEDIA_FIELD, TelegramObject.gson.toJson(media));
    for (InputMedia inputMedia : media) {
      if (inputMedia.getFile().isPresent()) {
        InputStream file = inputMedia.getFile().get();
        String fileAttachName = inputMedia.getFileAttachName()
            .orElseThrow(NullPointerException::new);
        builder.addBinaryBody(fileAttachName, file, ContentType.APPLICATION_OCTET_STREAM, fileAttachName);
      }
    }
  }
  
  if (disableNotification != null)
    builder.addTextBody(DISABLE_NOTIFICATION_FIELD, disableNotification.toString());
  
  if (replyToMessageId != null)
    builder.addTextBody(REPLY_TO_MESSAGE_ID_FIELD, replyToMessageId.toString());
  
  return builder.build();
}
 
开发者ID:AgeOfWar,项目名称:Telejam,代码行数:28,代码来源:SendMediaGroup.java

示例15: postSlackCommandWithFile

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
private void postSlackCommandWithFile(Map<String, String> params, byte [] fileContent, String fileName, String command, SlackMessageHandleImpl handle) {
    URIBuilder uriBuilder = new URIBuilder();
    uriBuilder.setScheme(SLACK_API_SCHEME).setHost(SLACK_API_HOST).setPath(SLACK_API_PATH+"/"+command);
    for (Map.Entry<String, String> arg : params.entrySet())
    {
        uriBuilder.setParameter(arg.getKey(),arg.getValue());
    }
    HttpPost request = new HttpPost(uriBuilder.toString());
    HttpClient client = getHttpClient();
    MultipartEntityBuilder builder = MultipartEntityBuilder.create();
    try
    {
        builder.addBinaryBody("file",fileContent, ContentType.DEFAULT_BINARY,fileName);
        request.setEntity(builder.build());
        HttpResponse response = client.execute(request);
        String jsonResponse = ReaderUtils.readAll(new InputStreamReader(response.getEntity().getContent()));
        LOGGER.debug("PostMessage return: " + jsonResponse);
        ParsedSlackReply reply = SlackJSONReplyParser.decode(parseObject(jsonResponse),this);
        handle.setReply(reply);
    }
    catch (Exception e)
    {
        // TODO : improve exception handling
        e.printStackTrace();
    }
}
 
开发者ID:riversun,项目名称:slacklet,代码行数:27,代码来源:SlackWebSocketSessionImpl.java


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