[英]Jersey I can't authorize the user when uploading files
在默認函數中,我可以使用ContainerRequestContext requestCtx
從請求中獲取securitycontext和用戶名。
但是由於某種原因,在使用MediaType.MULTIPART_FORM_DATA
的函數中使用此函數時,出現此錯誤:
org.glassfish.jersey.server.model.ModelValidationException: Validation of the application resource model has failed during application initialization.
碼:
@POST
@Path("{albumcode}")
@RolesAllowed("user")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadPicture(@PathParam("code") String code,
FormDataMultiPart multipart,
ContainerRequestContext requestCtx) {
如果沒有ContainerRequestContext requestCtx
那么上面的代碼就可以正常工作。
從我的ContainerRequestContext
獲取數據並能夠同時上傳文件的最佳方法是什么?
閱讀隨機帖子時找到了解決方案。 我發現在我的ContainerRequestContext requestCtx
的@Context
添加@Context
批注可以解決該問題。
我希望我可以幫助其他人解決這個問題,但找不到與此相關的其他答案。
@POST
@Path("{albumcode}")
@RolesAllowed("user")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadPicture(@PathParam("code") String code,
FormDataMultiPart multipart,
@Context ContainerRequestContext requestCtx) {
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.