Reputation: 326
I'm trying to upload a file from my spring boot application to Amazon s3.
When I upload the file using POSTMAN, the files are successfully uploaded to s3. However, when I try to upload file from swagger it responds with a status code of 200 but does not upload the file and in my spring boot application, it throws a null pointer exception.
Is this CORS issue (I have even tried to enable CORS in spring boot config)? Or am I doing something wrong like need to add config to my swagger or something?
Here is the controller code -
@PostMapping(value = "/uploadFile" )
public JSONObject uploadFile(MultipartFile[] file) {
return this.amazonClient.uploadFile(file);
}
Here is POSTMAN request which is working fine -
Here is the swagger request which does not work -
EDIT:
After making changes to the Controller
method like this:
@RequestMapping(value = "/uploadFile",method = RequestMethod.POST, consumes = { "multipart/form-data" })
//@PostMapping(value = "/uploadFile" ) // consumes = MediaType.MULTIPART_FORM_DATA_VALUE
public JSONObject uploadFile(@RequestPart("file") MultipartFile[] file) {
return this.amazonClient.uploadFile(file);
}
I am getting the following curl request now on Swagger
:
curl -X POST "http://localhost:8080/storage/uploadFile" -H "accept: */*" -H "Content-Type: multipart/form-data" -F "file={}"
You can clearly see that the file
parameter is going empty. Any thoughts?
Upvotes: 6
Views: 5827
Reputation: 21
I think that , Swagger does not support properly with file uploading or downloading when I tried to upload and download file, uploading works fine but when I download it with swagger this file can not open but, using with postman everything work
Upvotes: 1