@Override public String getContentType() { return this.part.getContentType(); }
@Override public String getContentType() { return this.part.getContentType(); }
@Override public String getContentType() { return part.getContentType(); }
@Override public String getMultipartContentType(String paramOrFileName) { try { Part part = getPart(paramOrFileName); return (part != null ? part.getContentType() : null); } catch (Throwable ex) { throw new MultipartException("Could not access multipart servlet request", ex); } }
protected static InputStream maybeDecompress(Part item) throws IOException { InputStream in = item.getInputStream(); String contentType = item.getContentType(); if (contentType != null) { switch (contentType) { case "application/zip": in = new ZipInputStream(in); break; case "application/gzip": case "application/x-gzip": in = new GZIPInputStream(in); break; } } return in; }
@Override public String getMultipartContentType(String paramOrFileName) { try { Part part = getPart(paramOrFileName); return (part != null ? part.getContentType() : null); } catch (Throwable ex) { throw new MultipartException("Could not access multipart servlet request", ex); } }
/** * Gets the content type of this part. * * @return The content type of this part. */ public String getContentType() { return part.getContentType(); }
@Override public String getContentType() { return part.getContentType(); }
private FlowFile savePartAttributes(ProcessContext context, ProcessSession session, Part part, FlowFile flowFile, final int i, final int allPartsCount) { final Map<String, String> attributes = new HashMap<>(); for (String headerName : part.getHeaderNames()) { final String headerValue = part.getHeader(headerName); putAttribute(attributes, "http.headers.multipart." + headerName, headerValue); } putAttribute(attributes, "http.multipart.size", part.getSize()); putAttribute(attributes, "http.multipart.content.type", part.getContentType()); putAttribute(attributes, "http.multipart.name", part.getName()); putAttribute(attributes, "http.multipart.filename", part.getSubmittedFileName()); putAttribute(attributes, "http.multipart.fragments.sequence.number", i+1); putAttribute(attributes, "http.multipart.fragments.total.number", allPartsCount); return session.putAllAttributes(flowFile, attributes); }
@Override public String getContentType() { return part.getContentType(); }
private FlowFile savePartDetailsAsAttributes(final ProcessSession session, final Part part, final FlowFile flowFile, final int sequenceNumber, final int allPartsCount) { final Map<String, String> attributes = new HashMap<>(); for (String headerName : part.getHeaderNames()) { final String headerValue = part.getHeader(headerName); putAttribute(attributes, "http.headers.multipart." + headerName, headerValue); } putAttribute(attributes, "http.multipart.size", part.getSize()); putAttribute(attributes, "http.multipart.content.type", part.getContentType()); putAttribute(attributes, "http.multipart.name", part.getName()); putAttribute(attributes, "http.multipart.filename", part.getSubmittedFileName()); putAttribute(attributes, "http.multipart.fragments.sequence.number", sequenceNumber + 1); putAttribute(attributes, "http.multipart.fragments.total.number", allPartsCount); return session.putAllAttributes(flowFile, attributes); }
private OperationRequestPart createOperationRequestPart(Part part) throws IOException { HttpHeaders partHeaders = extractHeaders(part); List<String> contentTypeHeader = partHeaders.get(HttpHeaders.CONTENT_TYPE); if (part.getContentType() != null && contentTypeHeader == null) { partHeaders.setContentType(MediaType.parseMediaType(part.getContentType())); } return new OperationRequestPartFactory().create(part.getName(), StringUtils.hasText(part.getSubmittedFileName()) ? part.getSubmittedFileName() : null, FileCopyUtils.copyToByteArray(part.getInputStream()), partHeaders); }
public static void prepareDownloadHeader(HttpServletResponseEx responseEx, Part part) { if (responseEx.getHeader(HttpHeaders.CONTENT_LENGTH.toString()) == null) { responseEx.setChunked(true); } if (responseEx.getHeader(HttpHeaders.CONTENT_TYPE.toString()) == null) { responseEx.setHeader(HttpHeaders.CONTENT_TYPE.toString(), part.getContentType()); } if (responseEx.getHeader(javax.ws.rs.core.HttpHeaders.CONTENT_DISPOSITION) == null) { // to support chinese and space filename in firefox // must use "filename*", (https://tools.ietf.org/html/rtf6266) String encodedFileName = HttpUtils.uriEncodePath(part.getSubmittedFileName()); responseEx.setHeader(javax.ws.rs.core.HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + encodedFileName + ";filename*=utf-8''" + encodedFileName); } }
/** * @throws IllegalStateException if the request is too large */ public String getContentType( String partName ) { String result = null; if (isMultiPartRequest) { try { Part p = httpRequest.getPart(partName); if (p != null) result = p.getContentType(); } catch (IOException ioe) { log(ioe); } catch (ServletException se) { log(se); } catch (IllegalStateException ise) { log(ise); throw ise; } } return result; }
IoCopy(p.getInputStream(), bytes); params.add(p.getName(), bytes.toByteArray()); if (p.getContentType() != null) params.add(p.getName()+CONTENT_TYPE_SUFFIX, p.getContentType());
long size = 0; try { if (part.getContentType() == null || !part.getContentType().toLowerCase() .startsWith("image/")) continue;
@Override public String getContentType() { return part.getContentType(); } }
protected Buffer fileBoundaryInfo(String boundary, String name, Part part) { Buffer buffer = Buffer.buffer(); buffer.appendString("\r\n"); buffer.appendString("--" + boundary + "\r\n"); buffer.appendString("Content-Disposition: form-data; name=\"") .appendString(name) .appendString("\"; filename=\"") .appendString(part.getSubmittedFileName() != null ? part.getSubmittedFileName() : "null") .appendString("\"\r\n"); buffer.appendString("Content-Type: ").appendString(part.getContentType()).appendString("\r\n"); buffer.appendString("Content-Transfer-Encoding: binary\r\n"); buffer.appendString("\r\n"); return buffer; }
@Test public void requestWithPartWithContentType() throws Exception { MockHttpServletRequest mockRequest = MockMvcRequestBuilders.get("/foo") .buildRequest(new MockServletContext()); Part mockPart = mock(Part.class); given(mockPart.getHeaderNames()).willReturn(Arrays.asList("a", "b")); given(mockPart.getHeaders("a")).willReturn(Arrays.asList("alpha")); given(mockPart.getHeaders("b")).willReturn(Arrays.asList("bravo", "banana")); given(mockPart.getInputStream()) .willReturn(new ByteArrayInputStream(new byte[] { 1, 2, 3, 4 })); given(mockPart.getName()).willReturn("part-name"); given(mockPart.getSubmittedFileName()).willReturn("submitted.png"); given(mockPart.getContentType()).willReturn("image/png"); mockRequest.addPart(mockPart); OperationRequest request = this.factory.convert(mockRequest); assertThat(request.getParts().size()).isEqualTo(1); OperationRequestPart part = request.getParts().iterator().next(); assertThat(part.getName()).isEqualTo("part-name"); assertThat(part.getSubmittedFileName()).isEqualTo("submitted.png"); assertThat(part.getHeaders().getContentType()).isEqualTo(MediaType.IMAGE_PNG); assertThat(part.getHeaders().get("a")).containsExactly("alpha"); assertThat(part.getHeaders().get("b")).containsExactly("bravo", "banana"); assertThat(part.getContent()).isEqualTo(new byte[] { 1, 2, 3, 4 }); }
/** * Constructor */ ServletPartFileItem(Part part) { Args.notNull(part, "part"); this.part = part; String contentType = part.getContentType(); this.isFormField = contentType == null; }