org.apache.commons.httpclient.methods.multipart.ByteArrayPartSource Java Examples
The following examples show how to use
org.apache.commons.httpclient.methods.multipart.ByteArrayPartSource.
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: UploadServletTest.java From lutece-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
private MockHttpServletRequest getMultipartRequest( ) throws Exception { MockHttpServletRequest request = new MockHttpServletRequest( ); byte [ ] fileContent = new byte [ ] { 1, 2, 3 }; Part [ ] parts = new Part [ ] { new FilePart( "file1", new ByteArrayPartSource( "file1", fileContent ) ) }; MultipartRequestEntity multipartRequestEntity = new MultipartRequestEntity( parts, new PostMethod( ).getParams( ) ); // Serialize request body ByteArrayOutputStream requestContent = new ByteArrayOutputStream( ); multipartRequestEntity.writeRequest( requestContent ); // Set request body to HTTP servlet request request.setContent( requestContent.toByteArray( ) ); // Set content type to HTTP servlet request (important, includes Mime boundary string) request.setContentType( multipartRequestEntity.getContentType( ) ); request.setMethod( "POST" ); return request; }
Example #2
Source File: RestConsumer.java From RestServices with Apache License 2.0 | 5 votes |
private static void addFilePart(final IContext context, String partname, final IMendixObject source, List<Part> parts) throws IOException { ByteArrayPartSource p = new ByteArrayPartSource( getFileDocumentFileName(context, source), IOUtils.toByteArray(Core.getFileDocumentContent(context, source))); parts.add(new FilePart(partname, p)); }
Example #3
Source File: Telegram.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
private static Part[] createSendPhotoRequestParts(TelegramBot bot, byte[] image, String imageType, String caption) { List<Part> partList = new ArrayList<>(); partList.add(new StringPart("chat_id", bot.getChatId())); partList.add(new FilePart("photo", new ByteArrayPartSource(String.format("image.%s", imageType), image))); if (StringUtils.isNotBlank(caption)) { partList.add(new StringPart("caption", caption, "UTF-8")); } if (StringUtils.isNotBlank(bot.getParseMode())) { partList.add(new StringPart("parse_mode", bot.getParseMode())); } return partList.toArray(new Part[0]); }
Example #4
Source File: DifidoClient.java From difido-reports with Apache License 2.0 | 4 votes |
public void addFile(final int executionId, final String uid, final byte[] bytes, String fileName) throws Exception { Part[] parts = new Part[] { new FilePart("file", new ByteArrayPartSource(fileName, bytes))}; addFile(executionId,uid,parts); }