Reputation: 915
I am invoking the following service using a curl command:
@RequestMapping(value = "/api/uploadFile", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<String>> uploadFile(@RequestParam("file") MultipartFile multipartFile, @RequestHeader("Authorization") String authCredentials) {...}
It uses basic authentication and fileupload is needed as a multipart file.
How do I invoke this using a curl command?
I am trying this but getting an error saying illegal base64 character:
curl -i -H 'Authorization:Basic username:password' -H 'Accept:application/json' -F 'file=@./application.properties' http://hostname/api/uploadFile/
Error:
java.lang.IllegalArgumentException: Illegal base64 character 3a
at java.util.Base64$Decoder.decode0(Base64.java:714) ~[na:1.8.0_121]
at java.util.Base64$Decoder.decode(Base64.java:526) ~[na:1.8.0_121]
at java.util.Base64$Decoder.decode(Base64.java:549) ~[na:1.8.0_121]
Upvotes: 0
Views: 5071
Reputation: 58134
The Authorization:
header is wrong.
Let curl convert the user name and password to a HTTP authentication header instead with -u:
curl -i -u 'username:password' -H 'Accept:application/json' -F 'file=@./application.properties' http://hostname/api/uploadFile/
Upvotes: 1