List of usage examples for org.springframework.core.io PathResource PathResource
public PathResource(URI uri)
From source file:objective.taskboard.utils.IOUtilities.java
public static Resource asResource(Path path) { return new PathResource(path); }
From source file:org.apache.servicecomb.demo.springmvc.client.CodeFirstRestTemplateSpringmvc.java
private void testUpload(RestTemplate template, String cseUrlPrefix) throws IOException { String file1Content = "hello world"; File file1 = File.createTempFile(" ", ".txt"); FileUtils.writeStringToFile(file1, file1Content); String file2Content = " bonjour"; File someFile = File.createTempFile("upload2", ".txt"); FileUtils.writeStringToFile(someFile, file2Content); String expect = String.format("%s:%s:%s\n" + "%s:%s:%s", file1.getName(), MediaType.TEXT_PLAIN_VALUE, file1Content, someFile.getName(), MediaType.TEXT_PLAIN_VALUE, file2Content); String result = testRestTemplateUpload(template, cseUrlPrefix, file1, someFile); TestMgr.check(expect, result);//w w w .j ava 2 s. com MultiValueMap<String, Object> map = new LinkedMultiValueMap<>(); map.add("file1", new FileSystemResource(file1)); result = template.postForObject(cseUrlPrefix + "/upload1", new HttpEntity<>(map), String.class); result = uploadPartAndFile.fileUpload(new FilePart(null, file1), someFile); TestMgr.check(expect, result); expect = String.format("null:%s:%s\n" + "%s:%s:%s", MediaType.APPLICATION_OCTET_STREAM_VALUE, file1Content, someFile.getName(), MediaType.TEXT_PLAIN_VALUE, file2Content); result = uploadStreamAndResource.fileUpload( new ByteArrayInputStream(file1Content.getBytes(StandardCharsets.UTF_8)), new PathResource(someFile.getAbsolutePath())); TestMgr.check(expect, result); }