List of usage examples for io.netty.handler.codec.http.multipart MemoryFileUpload MemoryFileUpload
public MemoryFileUpload(String name, String filename, String contentType, String contentTransferEncoding, Charset charset, long size)
From source file:com.github.ambry.frontend.FrontendIntegrationTest.java
License:Open Source License
/** * Creates a {@link HttpPostRequestEncoder} that encodes the given {@code request} and {@code blobContent}. * @param request the {@link HttpRequest} containing headers and other metadata about the request. * @param blobContent the {@link ByteBuffer} that represents the content of the blob. * @param usermetadata the {@link ByteBuffer} that represents user metadata * @return a {@link HttpPostRequestEncoder} that can encode the {@code request} and {@code blobContent}. * @throws HttpPostRequestEncoder.ErrorDataEncoderException * @throws IOException/*from w ww .j a v a 2s . c om*/ */ private HttpPostRequestEncoder createEncoder(HttpRequest request, ByteBuffer blobContent, ByteBuffer usermetadata) throws HttpPostRequestEncoder.ErrorDataEncoderException, IOException { HttpDataFactory httpDataFactory = new DefaultHttpDataFactory(false); HttpPostRequestEncoder encoder = new HttpPostRequestEncoder(httpDataFactory, request, true); FileUpload fileUpload = new MemoryFileUpload(RestUtils.MultipartPost.BLOB_PART, RestUtils.MultipartPost.BLOB_PART, "application/octet-stream", "", Charset.forName("UTF-8"), blobContent.remaining()); fileUpload.setContent(Unpooled.wrappedBuffer(blobContent)); encoder.addBodyHttpData(fileUpload); fileUpload = new MemoryFileUpload(RestUtils.MultipartPost.USER_METADATA_PART, RestUtils.MultipartPost.USER_METADATA_PART, "application/octet-stream", "", Charset.forName("UTF-8"), usermetadata.remaining()); fileUpload.setContent(Unpooled.wrappedBuffer(usermetadata)); encoder.addBodyHttpData(fileUpload); return encoder; }
From source file:com.github.ambry.rest.NettyMessageProcessorTest.java
License:Open Source License
/** * Creates a {@link HttpPostRequestEncoder} that encodes the given {@code request} and {@code blobContent}. * @param request the {@link HttpRequest} containing headers and other metadata about the request. * @param blobContent the {@link ByteBuffer} that represents the content of the blob. * @return a {@link HttpPostRequestEncoder} that can encode the {@code request} and {@code blobContent}. * @throws HttpPostRequestEncoder.ErrorDataEncoderException * @throws IOException/*from w w w . ja v a2 s . c o m*/ */ private HttpPostRequestEncoder createEncoder(HttpRequest request, ByteBuffer blobContent) throws HttpPostRequestEncoder.ErrorDataEncoderException, IOException { HttpDataFactory httpDataFactory = new DefaultHttpDataFactory(false); HttpPostRequestEncoder encoder = new HttpPostRequestEncoder(httpDataFactory, request, true); FileUpload fileUpload = new MemoryFileUpload(RestUtils.MultipartPost.BLOB_PART, RestUtils.MultipartPost.BLOB_PART, "application/octet-stream", "", Charset.forName("UTF-8"), blobContent.remaining()); fileUpload.setContent(Unpooled.wrappedBuffer(blobContent)); encoder.addBodyHttpData(fileUpload); return encoder; }
From source file:com.github.ambry.rest.NettyMultipartRequestTest.java
License:Open Source License
/** * Creates a {@link HttpPostRequestEncoder} that encodes the given {@code request} and {@code parts}. * @param request the {@link HttpRequest} containing headers and other metadata about the request. * @param parts the {@link InMemoryFile}s that will form the parts of the request. * @return a {@link HttpPostRequestEncoder} that can encode the {@code request} and {@code parts}. * @throws HttpPostRequestEncoder.ErrorDataEncoderException * @throws IOException/*from www . j a v a 2 s. c o m*/ */ private HttpPostRequestEncoder createEncoder(HttpRequest request, InMemoryFile[] parts) throws HttpPostRequestEncoder.ErrorDataEncoderException, IOException { HttpDataFactory httpDataFactory = new DefaultHttpDataFactory(false); HttpPostRequestEncoder encoder = new HttpPostRequestEncoder(httpDataFactory, request, true); if (parts != null) { for (InMemoryFile part : parts) { FileUpload fileUpload = new MemoryFileUpload(part.name, part.name, "application/octet-stream", "", Charset.forName("UTF-8"), part.content.remaining()); fileUpload.setContent(Unpooled.wrappedBuffer(part.content)); encoder.addBodyHttpData(fileUpload); } } return encoder; }
From source file:reactor.ipc.netty.http.client.HttpClientFormEncoder.java
License:Open Source License
@Override public HttpClientRequest.Form file(String name, String filename, InputStream stream, String contentType) { Objects.requireNonNull(name, "name"); Objects.requireNonNull(stream, "stream"); try {// w w w .ja v a 2s . c o m String scontentType = contentType; if (contentType == null) { scontentType = DEFAULT_BINARY_CONTENT_TYPE; } MemoryFileUpload fileUpload = new MemoryFileUpload(name, filename, scontentType, DEFAULT_TRANSFER_ENCODING, charset, -1); fileUpload.setMaxSize(-1); fileUpload.setContent(stream); addBodyHttpData(fileUpload); } catch (ErrorDataEncoderException e) { throw Exceptions.propagate(e); } catch (IOException e) { throw Exceptions.propagate(new ErrorDataEncoderException(e)); } return this; }
From source file:reactor.ipc.netty.http.client.HttpClientFormEncoder.java
License:Open Source License
@Override public HttpClientRequest.Form textFile(String name, InputStream stream, String contentType) { Objects.requireNonNull(name, "name"); Objects.requireNonNull(stream, "stream"); try {//from w w w . ja va2s.c o m String scontentType = contentType; if (contentType == null) { scontentType = DEFAULT_TEXT_CONTENT_TYPE; } MemoryFileUpload fileUpload = new MemoryFileUpload(name, "", scontentType, null, charset, -1); fileUpload.setMaxSize(-1); fileUpload.setContent(stream); addBodyHttpData(fileUpload); } catch (ErrorDataEncoderException e) { throw Exceptions.propagate(e); } catch (IOException e) { throw Exceptions.propagate(new ErrorDataEncoderException(e)); } return this; }