@Override public String getContentType() { return fileUpload.getContentType(); }
/** * @return The content type of the http data */ public Optional<MediaType> getContentType() { if (data instanceof FileUpload) { return Optional.of(MediaType.of(((FileUpload) data).getContentType())); } else { return Optional.empty(); } }
@Override public Optional<MediaType> getContentType() { return Optional.of(MediaType.of(fileUpload.getContentType())); }
@Override public Optional<MediaType> getContentType() { return Optional.of(new MediaType(fileUpload.getContentType())); }
private Optional<String> header(final String name) { if (name.equalsIgnoreCase("content-transfer-encoding")) { return Optional.of(data.getContentTransferEncoding()); } else if (name.equalsIgnoreCase("content-disposition")) { return Optional.of("form-data; name=\"" + data.getName() + "\"; filename=\"" + data.getFilename() + "\""); } else if (name.equalsIgnoreCase("content-type")) { String cs = Optional.ofNullable(data.getCharset()) .map(it -> "; charset=" + it.name()) .orElse(""); return Optional.ofNullable(data.getContentType()) .flatMap(it -> Optional.of(it + cs)); } else { return Optional.empty(); } }
/** * Parse FileUpload to {@link FileItem}. * * @param fileUpload netty http file upload */ private void parseFileUpload(FileUpload fileUpload) throws IOException { if (!fileUpload.isCompleted()) { return; } FileItem fileItem = new FileItem(); fileItem.setName(fileUpload.getName()); fileItem.setFileName(fileUpload.getFilename()); // Upload the file is moved to the specified temporary file, // because FileUpload will be release after completion of the analysis. // tmpFile will be deleted automatically if they are used. Path tmpFile = Files.createTempFile( Paths.get(fileUpload.getFile().getParent()), "blade_", "_upload"); Path fileUploadPath = Paths.get(fileUpload.getFile().getPath()); Files.move(fileUploadPath, tmpFile, StandardCopyOption.REPLACE_EXISTING); fileItem.setFile(tmpFile.toFile()); fileItem.setPath(tmpFile.toFile().getPath()); fileItem.setContentType(fileUpload.getContentType()); fileItem.setLength(fileUpload.length()); fileItems.put(fileItem.getName(), fileItem); }
/** * Parse FileUpload to {@link FileItem}. * * @param fileUpload netty http file upload */ private void parseFileUpload(FileUpload fileUpload) throws IOException { if (!fileUpload.isCompleted()) { return; } FileItem fileItem = new FileItem(); fileItem.setName(fileUpload.getName()); fileItem.setFileName(fileUpload.getFilename()); // Upload the file is moved to the specified temporary file, // because FileUpload will be release after completion of the analysis. // tmpFile will be deleted automatically if they are used. Path tmpFile = Files.createTempFile( Paths.get(fileUpload.getFile().getParent()), "blade_", "_upload"); Path fileUploadPath = Paths.get(fileUpload.getFile().getPath()); Files.move(fileUploadPath, tmpFile, StandardCopyOption.REPLACE_EXISTING); fileItem.setFile(tmpFile.toFile()); fileItem.setPath(tmpFile.toFile().getPath()); fileItem.setContentType(fileUpload.getContentType()); fileItem.setLength(fileUpload.length()); fileItems.put(fileItem.getName(), fileItem); }
@Override public Optional<Object> convert(FileUpload object, Class<Object> targetType, ConversionContext context) { try { if (!object.isCompleted()) { return Optional.empty(); } String contentType = object.getContentType(); ByteBuf byteBuf = object.getByteBuf(); if (StringUtils.isNotEmpty(contentType)) { MediaType mediaType = new MediaType(contentType); Optional<MediaTypeCodec> registered = decoderRegistryProvider.get().findCodec(mediaType); if (registered.isPresent()) { MediaTypeCodec decoder = registered.get(); Object val = decoder.decode(targetType, new ByteBufInputStream(byteBuf)); return Optional.of(val); } else { return conversionService.convert(byteBuf, targetType, context); } } return conversionService.convert(byteBuf, targetType, context); } catch (Exception e) { context.reject(e); return Optional.empty(); } } }
@Override public void setContent(File file) throws IOException { checkSize(file.length()); if (file.length() > limitSize) { if (fileUpload instanceof MemoryFileUpload) { FileUpload memoryUpload = fileUpload; // change to Disk fileUpload = new DiskFileUpload(memoryUpload .getName(), memoryUpload.getFilename(), memoryUpload .getContentType(), memoryUpload .getContentTransferEncoding(), memoryUpload.getCharset(), definedSize); fileUpload.setMaxSize(maxSize); // release old upload memoryUpload.release(); } } fileUpload.setContent(file); }
@Override public void setContent(ByteBuf buffer) throws IOException { checkSize(buffer.readableBytes()); if (buffer.readableBytes() > limitSize) { if (fileUpload instanceof MemoryFileUpload) { FileUpload memoryUpload = fileUpload; // change to Disk fileUpload = new DiskFileUpload(memoryUpload .getName(), memoryUpload.getFilename(), memoryUpload .getContentType(), memoryUpload .getContentTransferEncoding(), memoryUpload.getCharset(), definedSize); fileUpload.setMaxSize(maxSize); // release old upload memoryUpload.release(); } } fileUpload.setContent(buffer); }
@Override public void addContent(ByteBuf buffer, boolean last) throws IOException { if (fileUpload instanceof MemoryFileUpload) { checkSize(fileUpload.length() + buffer.readableBytes()); if (fileUpload.length() + buffer.readableBytes() > limitSize) { DiskFileUpload diskFileUpload = new DiskFileUpload(fileUpload .getName(), fileUpload.getFilename(), fileUpload .getContentType(), fileUpload .getContentTransferEncoding(), fileUpload.getCharset(), definedSize); diskFileUpload.setMaxSize(maxSize); ByteBuf data = fileUpload.getByteBuf(); if (data != null && data.isReadable()) { diskFileUpload.addContent(data.retain(), false); } // release old upload fileUpload.release(); fileUpload = diskFileUpload; } } fileUpload.addContent(buffer, last); }
@Override public void setContent(InputStream inputStream) throws IOException { if (fileUpload instanceof MemoryFileUpload) { FileUpload memoryUpload = fileUpload; // change to Disk fileUpload = new DiskFileUpload(fileUpload .getName(), fileUpload.getFilename(), fileUpload .getContentType(), fileUpload .getContentTransferEncoding(), fileUpload.getCharset(), definedSize); fileUpload.setMaxSize(maxSize); // release old upload memoryUpload.release(); } fileUpload.setContent(inputStream); }
internal.addValue(HttpHeaderNames.CONTENT_TYPE + ": " + fileUpload.getContentType()); String contentTransferEncoding = fileUpload.getContentTransferEncoding(); if (contentTransferEncoding != null
@Override public String getContentType() { return fileUpload.getContentType(); }
@Override public String mimetype() { return upload.getContentType(); }
@Override public String getContentType() { return fileUpload.getContentType(); }
@Override public String getContentType() { return fileUpload.getContentType(); }
@Override public String getContentType() { return fileUpload.getContentType(); }
public void save(FileUploadEvent e) { FileUpload file = event.getFile(); String fileName = file.getFileName(); String contentType = file.getContentType(); byte[] content = file.getContents(); saveFile(content); } private void saveFile(byte[] data) { FileOutputStream fos = new FileOutputStream(DIR_NAME); fos.write(data); fos.close(); }
public HttpFile(final FileUpload data) { parameterName = data.getName(); fileName = data.getFilename(); contentType = data.getContentType(); inMemory = data.isInMemory(); try { file = data.getFile(); } catch (IOException e) { //not possible } }