Refine search
@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); }
/** * 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 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); }
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(); } }
if (fileUpload != null) { fileUpload.addContent(content.retain(), true); ((LazyResourceState) request.state()).fileUpload(fileUpload); } else { fileUpload.delete(); } else if (content.readableBytes() > 0) { log.debug("on LastHttpContent: " + content.readableBytes() + " bytes discarded!"); fileUpload.addContent(content.retain(), false); } else if (content.readableBytes() > 0) { log.debug("on HttpContent: " + content.readableBytes() + " bytes discarded!"); fileUpload.delete(); factory.createAttribute(original, "filename", filename); factory.createAttribute(original, CONTENT_LENGTH, contentLength); try { clen = Long.parseLong(contentLength); factory.createAttribute(original, CONTENT_TYPE, contentType); fileUpload = factory.createFileUpload(original, request.resourcePath().toString(), filename,
/** * Gets the content of this part as a <tt>ByteBuffer</tt>. * * <p>Because the contents of the file are released after being retrieved, * this method can only be called <strong>once</strong></p> * * @return The content of this part as a <tt>ByteBuffer</tt> * @throws IOException If an error occurs in retrieving the content */ @Override public ByteBuffer getByteBuffer() throws IOException { ByteBuf byteBuf = fileUpload.getByteBuf(); try { return byteBuf.nioBuffer(); } finally { byteBuf.release(); } }
/** * Get content length. * * @return Length of posted / uploaded content. */ @Override public long getContentLength() { if (fileUpload != null) { return fileUpload.length(); } if (buffer != null) { return buffer.readableBytes(); } return 0; }
/** * Gets the content of this part as a <tt>byte[]</tt>. * * <p>Because the contents of the file are released after being retrieved, * this method can only be called <strong>once</strong></p> * * @return The content of this part as a <tt>byte[]</tt> * @throws IOException If an error occurs in retrieving the content */ @Override public byte[] getBytes() throws IOException { ByteBuf byteBuf = fileUpload.getByteBuf(); try { return ByteBufUtil.getBytes(byteBuf); } finally { byteBuf.release(); } }
@SuppressWarnings("unchecked") private I decodeMultipart() { HttpPostMultipartRequestDecoder decoder = new HttpPostMultipartRequestDecoder(msg.request()); List<com.simplyti.service.api.multipart.FileUpload> files = decoder.getBodyHttpDatas().stream() .filter(data->data.getHttpDataType().equals(HttpDataType.FileUpload)) .map(FileUpload.class::cast) .map(data->new com.simplyti.service.api.multipart.FileUpload(data.content().retain(),data.getFilename())) .collect(Collectors.toList()); run(decoder::destroy); return (I) files; }
String key = encodeAttribute(fileUpload.getName(), charset); String value = encodeAttribute(fileUpload.getFilename(), charset); Attribute newattribute = factory.createAttribute(request, key, value); multipartHttpDatas.add(newattribute); globalBodySize += newattribute.getName().length() + 1 + newattribute.length() + 1; if (currentFileUpload != null && currentFileUpload.getName().equals(fileUpload.getName())) { && currentFileUpload.getName().equals(fileUpload.getName())) { StringBuilder replacement = new StringBuilder( 139 + multipartDataBoundary.length() + multipartMixedBoundary.length() * 2 + fileUpload.getFilename().length() + fileUpload.getName().length()) .append(HttpHeaderValues.NAME) .append("=\"") .append(fileUpload.getName()) .append("\"\r\n") if (!fileUpload.getFilename().isEmpty()) { replacement.append("; ") .append(HttpHeaderValues.FILENAME) .append("=\"") .append(fileUpload.getFilename()) .append('"'); if (fileUpload.getFilename().isEmpty()) { + HttpHeaderValues.FILENAME + "=\"" + fileUpload.getFilename() + "\"\r\n");
contentTransferEncoding = HttpPostBodyUtil.TransferEncodingMechanism.BINARY.value(); FileUpload fileUpload = factory.createFileUpload(request, name, filename, scontentType, contentTransferEncoding, null, file.length()); try { fileUpload.setContent(file); } catch (IOException e) { throw new ErrorDataEncoderException(e);
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 } }
public static MultipartFile create(FileUpload fileUpload) { try { MultipartFile _file = new MultipartFile(); _file.setContent(fileUpload.get()); _file.setContentType(fileUpload.getContentType()); _file.setSize(fileUpload.length()); _file.setName(fileUpload.getFilename()); return _file; } catch (Exception ex) { // ignore exception } return null; } }
try { if (LOG.isDebugEnabled()) { LOG.debug("Transferring file {} to location {}", fileUpload.getFilename(), destination); return destination != null && fileUpload.renameTo(destination); } catch (IOException e) { throw new MultipartException("Error transferring file: " + fileUpload.getName(), e);
if (data.getHttpDataType() == HttpDataType.FileUpload) { FileUpload fileUpload = (FileUpload) data; if (fileUpload.isCompleted()) { requestProcessed = true; String format = ImageStoreUtil.checkTemplateFormat(fileUpload.getFile().getAbsolutePath(), fileUpload.getFilename()); if(StringUtils.isNotBlank(format)) { String errorString = "File type mismatch between the sent file and the actual content. Received: " + format; return HttpResponseStatus.BAD_REQUEST; String status = storageResource.postUpload(uuid, fileUpload.getFile().getName(), processTimeout); if (status != null) { responseContent.append(status);
@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(); } } }
private void handleUploadFile(InterfaceHttpData data, Message uploadMessage) throws IOException{ FileForm fileForm = uploadMessage.fileForm; if(uploadMessage.fileForm == null){ uploadMessage.fileForm = fileForm = new FileForm(); } if (data.getHttpDataType() == HttpDataType.Attribute) { Attribute attribute = (Attribute) data; fileForm.attributes.put(attribute.getName(), attribute.getValue()); return; } if (data.getHttpDataType() == HttpDataType.FileUpload) { FileUpload fileUpload = (FileUpload) data; Message.FileUpload file = new Message.FileUpload(); file.fileName = fileUpload.getFilename(); file.contentType = fileUpload.getContentType(); file.data = fileUpload.get(); List<Message.FileUpload> uploads = fileForm.files.get(data.getName()); if(uploads == null){ uploads = new ArrayList<Message.FileUpload>(); fileForm.files.put(data.getName(), uploads); } uploads.add(file); } }
@Override public String getFilename() { return fileUpload.getFilename(); }
/** * Copy the {@link InputStream} data content into {@link FileUpload}. * * @see AbstractFilePart#setContent */ @Override void setContent(FileUpload fileUpload) throws IOException { fileUpload.setContent(data); }
contentType = HttpPostBodyUtil.DEFAULT_BINARY_CONTENT_TYPE; currentFileUpload = factory.createFileUpload(request, cleanString(nameAttribute.getValue()), cleanString(filenameAttribute.getValue()), contentType, mechanism.value(), localCharset, if (currentFileUpload.isCompleted()) {