@Override public File getFile() throws IOException { return fileUpload.getFile(); }
/** * 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 File getFile() throws IOException { return fileUpload.getFile(); }
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 File getFile() throws IOException { return fileUpload.getFile(); }
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 } }
@Override public File getFile() throws IOException { return fileUpload.getFile(); }
/** * 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 File getFile() throws IOException { return fileUpload.getFile(); }
/** * Get direct File reference to entire body content cached in a file if one exists. * * @return Temp File with body content or null if content is small enough to fit in memory */ @Override public File contentAsFile() { try { return fileUpload != null ? fileUpload.getFile() : null; } catch (IOException e) { throw new RuntimeException("Failed to retrieve fileUpload file: " + fileUpload, e); } }
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception { FileUpload file = (FileUpload)command; MultipartFile multipartFile = file.getFile(); String fileName=""; if(multipartFile!=null){ fileName = multipartFile.getOriginalFilename(); //do whatever you want } System.out.println("filename :" + fileName); return new ModelAndView("FileUploadSuccess","fileName",fileName); }
public class FileUploadController extends SimpleFormController{ public FileUploadController(){ setCommandClass(FileUpload.class); setCommandName("fileUploadForm"); } @Override protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception { FileUpload file = (FileUpload)command; MultipartFile multipartFile = file.getFile(); String fileName=""; if(multipartFile!=null){ fileName = multipartFile.getOriginalFilename(); //do whatever you want } return new ModelAndView("FileUploadSuccess","fileName",fileName); }
@Override public InputStream stream() { if (upload.isInMemory()) { // If the data is in memory, just return an input stream on the byte array. return new ByteArrayInputStream(bytes()); } else { // It's a file, probably huge, we can't get the bytes. try { return new FileInputStream(upload.getFile()); } catch (IOException e) { throw new RuntimeException("Cannot retrieve the content of the uploaded file", e); } } }
file.createNewFile(); try (FileChannel inputChannel = new FileInputStream(fileUpload.getFile()).getChannel(); FileChannel outputChannel = new FileOutputStream(file).getChannel()) { outputChannel.transferFrom(inputChannel, 0, inputChannel.size()); sendSimpleResponse(ctx,CREATED,"file name: " +file.getAbsolutePath());
/** * 填充参数 * * @param data InterfaceHttpData */ protected void putParam(InterfaceHttpData data) { final HttpDataType dataType = data.getHttpDataType(); if (dataType == HttpDataType.Attribute) { //普通参数 Attribute attribute = (Attribute) data; try { this.putParam(attribute.getName(), attribute.getValue()); } catch (IOException e) { log.error(e); } }else if(dataType == HttpDataType.FileUpload){ //文件 FileUpload fileUpload = (FileUpload) data; if(fileUpload.isCompleted()){ try { this.putParam(data.getName(), fileUpload.getFile()); } catch (IOException e) { log.error(e, "Get file param [{}] error!", data.getName()); } } } }