【发布时间】:2019-11-05 13:54:06
【问题描述】:
我有一个这样的类,应该将文件上传到亚马逊 s3 但我无法到达端点。当我执行http://localhost:8088/api/user/all 时,我正在使用邮递员,它工作正常。但上传返回 401 未经授权。我尝试调试,但我的请求甚至没有进入控制器
@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 上找到了如何使用 POSTMAN 上传文件,我使用了他们的示例,但结果相同,我什至无法调试,因为请求没有命中方法,就好像我的 url 错误一样。
这是我对邮递员的要求 http://localhost:8088/api/upload 还使用 Form-data name key=ile 并从我的电脑中选择一个文件,我尝试过选择标题和不选择标题,我还在控制器中同时使用了 RequestPart 和 RequestBody。
有什么建议吗?
有时我会进入我的环境(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
【问题讨论】:
标签: java file file-upload multipart