Follow along with the video below to see how to install our site as a web app on your home screen.
Anmerkung: This feature may not be available in some browsers.
rateLimiter.acquire();
String serviceURL = ....;
HttpHeaders headers = new HttpHeaders();
headers.set("Authorization", "Basic " + base64String);
headers.setAccept(Arrays.asList(new MediaType[]{MediaType.MULTIPART_FORM_DATA}));
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
body.add("upload_product_image", imageFile);
body.add("filename", fileName);
body.add(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA);
HttpEntity<MultiValueMap<String, Object>> entity = new HttpEntity<>(body, headers);
ResponseEntity<String> response = restTemplate.exchange(serviceURL, HttpMethod.POST, entity, String.class);
URI : https://blabla.com/v2/images
2021-08-19 12:40:48.270 DEBUG 23511 --- [export_Worker-1] .a.u.a.RequestResponseLoggingInterceptor : Method : POST
2021-08-19 12:40:48.271 DEBUG 23511 --- [export_Worker-1] .a.u.a.RequestResponseLoggingInterceptor : Headers : [Accept:"multipart/form-data", Authorization:"Basic c3VwcG9ydEBpbXBvcnQyc2hvcC5jb206WGJwdDk0Nyo=", User-Agent:"ddddd", Content-Type:"multipart/form-data;boundary=QoLFGmhtNdv6oXHe0KpWk1mxQOgjGoX6_GS", Content-Length:"723"]
2021-08-19 12:40:48.272 DEBUG 23511 --- [export_Worker-1] .a.u.a.RequestResponseLoggingInterceptor : Request body: --QoLFGmhtNdv6oXHe0KpWk1mxQOgjGoX6_GS
Content-Disposition: form-data; name="upload_product_image"
Content-Type: application/json
"/Users/Downloads/8718475964735_a_en_hd_1.jpg"
--QoLFGmhtNdv6oXHe0KpWk1mxQOgjGoX6_GS
Content-Disposition: form-data; name="filename"
Content-Type: text/plain;charset=UTF-8
Content-Length: 27
8718475964735_a_en_hd_1.jpg
--QoLFGmhtNdv6oXHe0KpWk1mxQOgjGoX6_GS
Content-Disposition: form-data; name="Content-Type"
Content-Type: application/json
{"type":"multipart","subtype":"form-data","parameters":{},"qualityValue":1.0,"wildcardType":false,"wildcardSubtype":false,"subtypeSuffix":null,"charset":null,"concrete":true}
--QoLFGmhtNdv6oXHe0KpWk1mxQOgjGoX6_GS--
headers.setAccept(Arrays.asList(new MediaType[]{MediaType.MULTIPART_FORM_DATA}));
baeldung hat gesagt.:In our example, the getTestFile( ) method generates a dummy file on the fly and returns a FileSystemResource:
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
MultiValueMap<String, String> fileMap = new LinkedMultiValueMap<>();
ContentDisposition contentDisposition = ContentDisposition
.builder("form-data")
.name("filename")
.filename(fileName)
.build();
fileMap.add(HttpHeaders.CONTENT_DISPOSITION, contentDisposition.toString());
byte[] fileContent = new byte[0];
try {
fileContent = FileUtils.readFileToByteArray(imageFile);
} catch (IOException e) {
e.printStackTrace();
}
HttpEntity<byte[]> fileEntity = new HttpEntity<>(fileContent, fileMap);
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
body.add("file", fileEntity);
body.add("filename", fileName);
HttpEntity<MultiValueMap<String, Object>> requestEntity =
new HttpEntity<>(body, headers);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
body.add("file", new FileSystemResource(imageFile));
body.add("filename", fileName);
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);