I am trying to upload a file with angular and spring boot, and it is throwing error 415 "unsupported media type" & "Missing or Invalid Url".
The api works fine when tested with Postman. But in Postman also, we need to pass content type as application/json for one of the two form-data values i.e. pathUrl. Postman Upload
There are 2 ways in which I am converting data before sending request to upload :
- I am trying to convert data before sending request like below :
let formData = new FormData(); formData.append('file', files[0]); formData.append('pathUrl', JSON.stringify(pathUrl));
I am getting this error for above try: "status: 415, error: "Unsupported Media Type","
- I am trying to convert data again as below so that I am able to pass content type as application/json for pathUrl :
let formData = new FormData(); let request = new Blob([JSON.stringify({ pathUrl: pathUrl }) ], { type: application/json, }); formData.append('file', files[0]); formData.append('pathUrl', request);
I am getting thie error for above try : "Missing or Invalid Url".
What am I doing wrong? How do I need to pass data so that it works like how it is working in Postman as shown above.
Could anyone please help. Thanks in advance.