Example usage for org.springframework.web.multipart MultipartFile getInputStream

List of usage examples for org.springframework.web.multipart MultipartFile getInputStream

Introduction

In this page you can find the example usage for org.springframework.web.multipart MultipartFile getInputStream.

Prototype

@Override
InputStream getInputStream() throws IOException;

Source Link

Document

Return an InputStream to read the contents of the file from.

Usage

From source file:de.whs.poodle.repositories.FileRepository.java

public int uploadFile(MultipartFile file) throws IOException {
    InputStream in = file.getInputStream();

    KeyHolder keyHolder = new GeneratedKeyHolder();
    jdbc.update(con -> {/*from w w w . j  a va2 s.c  om*/
        PreparedStatement ps = con.prepareStatement(
                "INSERT INTO uploaded_file(data,mimetype,filename) VALUES(?,?,?)", new String[] { "id" });

        ps.setBinaryStream(1, in, file.getSize());
        ps.setString(2, file.getContentType());
        ps.setString(3, file.getOriginalFilename());
        return ps;
    }, keyHolder);

    return keyHolder.getKey().intValue();
}

From source file:io.lavagna.web.api.UsersAdministrationController.java

@RequestMapping(value = "/api/user/bulk-insert", method = RequestMethod.POST)
public void createUsers(@RequestParam("file") MultipartFile file) throws IOException {
    try (InputStream is = file.getInputStream();
            InputStreamReader isr = new InputStreamReader(is, StandardCharsets.UTF_8)) {
        List<UserToCreate> usersToCreate = Json.GSON.fromJson(isr, userToCreateListType);
        userService.createUsers(usersToCreate);
    }/*from   w ww  . j a  va2s .c  o  m*/
}

From source file:org.bonitasoft.web.designer.controller.ImportController.java

private Path unzip(MultipartFile file) {
    try (InputStream is = file.getInputStream()) {
        return unzip.unzipInTempDir(is, "pageDesignerImport");
    } catch (ZipException e) {
        throw new ImportException(CANNOT_OPEN_ZIP, "Cannot open zip file", e);
    } catch (IOException e) {
        throw new ServerImportException("Error while unzipping zip file", e);
    }/*from   ww  w. ja  va2 s .co m*/
}

From source file:gov.nih.nci.ncicb.tcga.dcc.datareports.web.SubmissionReportController.java

@RequestMapping(value = SubmissionReportConstants.SUBMISSION_REPORT_URL, method = RequestMethod.POST)
public String handleSubmission(final ModelMap model, final Submission submission, final BindingResult result) {
    try {/* w w  w  .  jav a2  s .c  o m*/
        if (result.hasErrors()) {
            for (ObjectError error : (List<ObjectError>) result.getAllErrors()) {
                logger.info("Error: " + error.getCode() + " - " + error.getDefaultMessage());
            }
            model.addAttribute("response", buildManualJsonResponse(false, "Upload failed"));
        } else {
            final MultipartFile file = submission.getFileData();
            parseUploadedFile(file.getInputStream());
            model.addAttribute("response", buildManualJsonResponse(true, file.getOriginalFilename()));
        }
    } catch (IOException iox) {
        logger.info(iox.getMessage());
    }
    return SubmissionReportConstants.SUBMISSION_REPORT_VIEW;
}

From source file:org.magnum.dataup.VideoUpController.java

private void saveVideo(Video v, MultipartFile videoData) throws IOException {
    videoDataMgr.saveVideoData(v, videoData.getInputStream());
}

From source file:biz.c24.io.spring.integration.transformer.IoUnmarshallingTransformerIUTests.java

@Test
public void canUnmarshalTextFromMultipartFile() throws Exception {

    byte[] valid1 = loadCsvBytes();
    MultipartFile file = mock(MultipartFile.class);
    when(file.getInputStream()).thenReturn(new ByteArrayInputStream(valid1));

    C24UnmarshallingTransformer transformer = new C24UnmarshallingTransformer(model,
            new TextualSourceFactory());

    Message message = MessageBuilder.withPayload(file).build();

    Message<?> outputMessage = transformer.transform(message);

    assertThat(outputMessage.getPayload(), notNullValue());
    assertThat(outputMessage.getPayload(), is(Employees.class));

    Employees employees = (Employees) outputMessage.getPayload();
}

From source file:org.openmrs.module.webservices.helper.ModuleFactoryWrapper.java

public Module parseModuleFile(MultipartFile file) throws IOException {
    return new ModuleFileParser(file.getInputStream()).parse();
}

From source file:com.greglturnquist.springagram.fileservice.s3.ApplicationController.java

@RequestMapping(method = RequestMethod.POST, value = "/files")
public ResponseEntity<?> newFile(@RequestParam("name") String filename,
        @RequestParam("file") MultipartFile file) {

    try {// w w w  .  j a  v  a 2 s.c  o m
        this.fileService.saveFile(file.getInputStream(), file.getSize(), filename);

        Link link = linkTo(methodOn(ApplicationController.class).getFile(filename)).withRel(filename);
        return ResponseEntity.created(new URI(link.getHref())).build();

    } catch (IOException | URISyntaxException e) {
        return ResponseEntity.badRequest().body("Couldn't process the request");
    }
}

From source file:com.slyak.services.file.domain.FileInfo.java

@SneakyThrows
public FileInfo(MultipartFile file) {
    this.size = file.getSize();
    this.name = file.getName();
    this.contentType = file.getContentType();
    this.inputStream = file.getInputStream();
}

From source file:nl.edia.sakai.tool.skinmanager.FileUploadAction.java

protected InputStream getFileInputStream(RequestContext context) throws IOException {
    InputStream inputStream = null;
    {/*from w  w w  .  j av  a  2  s  .c o  m*/
        ParameterMap requestParameters = context.getRequestParameters();
        MultipartFile file = requestParameters.getMultipartFile(fileParameterName);
        if (file != null) {
            inputStream = file.getInputStream();
        } else {
            Object attribute = ((HttpServletRequest) ((ServletExternalContext) context.getExternalContext())
                    .getNativeRequest()).getAttribute(fileParameterName);
            if (attribute instanceof FileItem) {
                inputStream = ((FileItem) attribute).getInputStream();
            }
        }
    }
    return inputStream;
}