I want to send a file and a json model at one post request.
My Request Mapping looks like that:
@ResponseBody
@RequestMapping(value = "/sftp/upload", method = RequestMethod.POST)
public ResponseEntity<SftpModel> upload(@RequestPart("file") MultipartFile file, @RequestPart("sftpModel") SftpModel sftpModel) {
My Json has this structure:
{
"sftpHost": "ftp01.Host.de",
"sftpPort": 22,
"sftpUser": "anyUser",
"sftpPassword": "anyPass",
"sftpRemoteDirectory": "/"
}
And the file is on my system.
I'm able to send the file
or the sftpModel
seperatly but not together. The error I receive is:
{
"timestamp": 1497336812907,
"status": 415,
"error": "Unsupported Media Type",
"exception": "org.springframework.web.HttpMediaTypeNotSupportedException",
"message": "Content type 'application/octet-stream' not supported",
"path": "/secure-data-transfer-service/sftp/upload"
}
I tried it with postman and curl. But no chance.
curl --form "file=@test.txt" --form "sftpModel={"sftpHost":"ftp01.Host.de","sftpPort":22,"sftpUser":"anyUser","sftpPassword":"anyPass","sftpRemoteDirectory":"/"}" http://localhost:8080/secure-data-transfer-service/sftp/upload
Is there any way to send both?