use of org.springframework.http.ContentDisposition in project spring-framework by spring-projects.
the class StandardMultipartHttpServletRequest method parseRequest.
private void parseRequest(HttpServletRequest request) {
try {
Collection<Part> parts = request.getParts();
this.multipartParameterNames = new LinkedHashSet<>(parts.size());
MultiValueMap<String, MultipartFile> files = new LinkedMultiValueMap<>(parts.size());
for (Part part : parts) {
String headerValue = part.getHeader(HttpHeaders.CONTENT_DISPOSITION);
ContentDisposition disposition = ContentDisposition.parse(headerValue);
String filename = disposition.getFilename();
if (filename != null) {
if (filename.startsWith("=?") && filename.endsWith("?=")) {
filename = MimeDelegate.decode(filename);
}
files.add(part.getName(), new StandardMultipartFile(part, filename));
} else {
this.multipartParameterNames.add(part.getName());
}
}
setMultipartFiles(files);
} catch (Throwable ex) {
handleParseFailure(ex);
}
}
use of org.springframework.http.ContentDisposition in project spring-framework by spring-projects.
the class ResourceHttpMessageReaderTests method readResourceAsMono.
@Test
void readResourceAsMono() throws IOException {
String filename = "test.txt";
String body = "Test resource content";
ContentDisposition contentDisposition = ContentDisposition.attachment().name("file").filename(filename).build();
MockClientHttpResponse response = new MockClientHttpResponse(HttpStatus.OK);
response.getHeaders().setContentType(MediaType.TEXT_PLAIN);
response.getHeaders().setContentDisposition(contentDisposition);
response.setBody(Mono.just(stringBuffer(body)));
Resource resource = reader.readMono(ResolvableType.forClass(ByteArrayResource.class), response, Collections.emptyMap()).block();
assertThat(resource).isNotNull();
assertThat(resource.getFilename()).isEqualTo(filename);
assertThat(resource.getInputStream()).hasContent(body);
}
use of org.springframework.http.ContentDisposition in project OsmAnd-tools by osmandapp.
the class GpxController method calculateSrtmAltitude.
public GPXFile calculateSrtmAltitude(GPXFile gpxFile, File[] missingFile) {
if (srtmLocation == null) {
return null;
}
if (srtmLocation.startsWith("http://") || srtmLocation.startsWith("https://")) {
String serverUrl = srtmLocation + "/gpx/process-srtm";
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GPXUtilities.writeGpx(new OutputStreamWriter(baos), gpxFile, null);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
MultiValueMap<String, String> fileMap = new LinkedMultiValueMap<>();
ContentDisposition contentDisposition = ContentDisposition.builder("form-data").name("file").filename("route.gpx").build();
fileMap.add(HttpHeaders.CONTENT_DISPOSITION, contentDisposition.toString());
HttpEntity<byte[]> fileEntity = new HttpEntity<>(baos.toByteArray(), fileMap);
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
body.add("file", fileEntity);
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<byte[]> response = restTemplate.postForEntity(serverUrl, requestEntity, byte[].class);
if (response.getStatusCode().is2xxSuccessful()) {
return GPXUtilities.loadGPXFile(new ByteArrayInputStream(response.getBody()));
} else {
return null;
}
} else {
File srtmFolder = new File(srtmLocation);
if (!srtmFolder.exists()) {
return null;
}
IndexHeightData hd = new IndexHeightData();
hd.setSrtmData(srtmFolder);
for (Track tr : gpxFile.tracks) {
for (TrkSegment s : tr.segments) {
for (int i = 0; i < s.points.size(); i++) {
WptPt wpt = s.points.get(i);
double h = hd.getPointHeight(wpt.lat, wpt.lon, missingFile);
if (h != IndexHeightData.INEXISTENT_HEIGHT) {
wpt.ele = h;
} else if (i == 0) {
return null;
}
}
}
}
}
return gpxFile;
}
Aggregations