Use curl to upload files

Curl curl curl curl curl curl curl curl curl curl curl curl curl curl curl curl curl curl curl curl curl curl curl curl curl curl , are commonly used to send HTTP POST requests on the command line, similar to what Postman does.

Curl curl curl curl curl curl curl curl curl curl curl curl curl

curl -X POST http://<someUrl> -F "file=@/path/to/aFile.txt"
Copy the code

Similar to postman

Curl uploads files in Spring’s RestTemplate

The following curl and Postman uploads files:

File file = File.createTempFile("aaa"."bbb");
FileUtils.writeStringToFile(file, mapper.writeValueAsString(message), "UTF-8");

MultiValueMap<String, Object> values = new LinkedMultiValueMap<String, Object>();
values.add("file".new FileSystemResource(file)); Curl = @/path/aFile = @/path/aFile

restTemplate.postForObject(URL, values, String.class);
Copy the code

reference

  1. curl document
  2. java – How I do the equivalent of this curl command using Spring’s RestTemplate? – Stack Overflow
  3. RestTemplate (Spring Framework 5.3.7 API)