Reputation: 2094
I have a class as such that should upload files to amazon s3 But i am not able to hit the endpoint. I am using postman when i perform http://localhost:8088/api/user/all it works fine . But uploading returns 401 unauthorized. I try to debug but my request does not even enter the controller
@CrossOrigin
@RequestMapping(value = "/api")
@RestController
public class PostController {
private static final Logger LOGGER = LogManager.getLogger();
@Autowired
private PhotoService photoService;
@Autowired
private UserService userService;
@RequestMapping(method = POST, value = "/upload")
public Photo submitPhoto(@RequestPart MultipartFile file) throws IOException {
LOGGER.debug("submitPhoto({})", file);
return photoService.savePhoto(file);
}
@RequestMapping(method = GET, value = "/user/all")
public List<User> loadAll() {
return this.userService.findAll();
}
}
So i found on SO how to upload file with POSTMAN i have used their examples but thesame result, I cant even debug because request is not hitting the method as if my url is wrong.
THis is my request to postman http://localhost:8088/api/upload also Using Form-data name key=ile and choosing a file from my pc, I have tried both with selecting headers and no headers, I have also used both RequestPart and RequestBody in my controller.
Any suggestions Please ?
At somepoint i am getting in my enviroment(Intellij)
org.apache.tomcat.util.http.Parameters : Character decoding failed. Parameter [���� JFIF �� �Photoshop 3.0 8BIM g( bFBMD01000aa80300001424000049540000a05600008b590000827a0000cbc30000eacb00004cd100007cd700003b640100 ��ICC_PROFILE lcms mntrRGB XYZ � ) 9acspAPPL �� �-lcms
desc � ^cprt \ wtpt h bkpt | rXYZ � gXYZ � bXYZ � rTRC � @gTRC � @bTRC � @desc c2 text FB XYZ �� �-XYZ 3 �XYZ o� 8� �XYZ b� �� �XYZ $� � ��curv ��ck�?Q4!�)�2;�FQw]�kpz���|�i�}���0���� C
db° §jʼ@9H<HY-²£W
âyÃèaæÛÒÉ<ÚzhY}SDúØydôâ<¹ôêe½<úú5<ôÝSl,iC:v¢s ¢ÄªÊ!y®²öãÖy:V·¬s®sé!ÒÜ/Dç5Ðj¶(,°ñ ñ"±B<®Jál®ZÑ`íYVÁ)ÂÊ°,$)Ö L³Z²"0)ÊÉcTKeL;Ó$è~Xu
é«2Ól©³6.Äî^] has been ignored. Note that the name and value quoted here may be corrupted due to the failed decoding. Use debug level logging to see the original, non-corrupted values.
Note: further occurrences of Parameter errors will be logged at DEBUG level
Upvotes: 2
Views: 404
Reputation: 2452
You should use a content type that's appropriate for binary data. application/octet-stream
is one option.
You can also change your code to use @RequestParam("file")
instead of @RequestPart
. Then use form data in body with "file"
as key.
Upvotes: 1