Quarkus를 사용하여 JAX-RS 서비스를 작성하고 있습니다. 내 서비스는 업로드 이미지 파일과 함께 이름, 생년월일 등의 간단한 사용자 프로필을 만들어야합니다. 멀티 파트 양식 업로드로이 작업을 수행하려고하는데 오류가 계속 발생합니다.
내 서비스 정의는 다음과 같습니다.
@Path("/profile")
@POST
@Consumes({MediaType.MULTIPART_FORM_DATA})
@Produces({ MediaType.APPLICATION_JSON })
public Response createStudentProfile(@MultipartForm ProfileFormBean profile);
내 ProfileFormBean
수업은 다음과 같습니다.
public class ProfileFormBean {
@FormParam("firstName")
@PartType(MediaType.TEXT_PLAIN)
private String firstName = null;
@FormParam("lastName")
@PartType(MediaType.TEXT_PLAIN)
private String lastName = null;
@FormParam("profileImage")
@PartType(MediaType.APPLICATION_OCTET_STREAM)
private byte[] profileImage = null;
...
}
내가 아는 한, 이것은 내 서비스가 파일 업로드를 수락하기에 충분할 것입니다. 나는 이것을 curl을 사용하여 테스트하려고 시도하고 있지만 그렇게 할 때 예외가 발생합니다. 내 curl 명령은 이름 / 성 속성을 설정하지 않고 파일 자체를 업로드하려고합니다.
curl -vki -H "Authorization: Bearer ${ACCESS_TOKEN}" \
-H 'Accepts: application/json' \
-F 'profileImage=@profile_image.jpg' \
http://localhost:8081/profile
이 명령의 출력은 다음과 같습니다.
curl -vki -H "Authorization: Bearer ${ACCESS_TOKEN}" \
> -H 'Accepts: application/json' \
> -F 'profileImage=@profile_image.jpg' \
> http://localhost:8081/profile
* Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8081 (#0)
> POST /profile HTTP/1.1
> Host: localhost:8081
> User-Agent: curl/7.54.0
> Accept: */*
> Authorization: Bearer eyJhbGciOiJSUzI1N...
> Accepts: application/json
> Content-Length: 11701
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=------------------------49161ebc82f19511
>
< HTTP/1.1 415 Unsupported Media Type
HTTP/1.1 415 Unsupported Media Type
< Content-Length: 0
Content-Length: 0
* HTTP error before end of send, stop sending
<
* Closing connection 0
그리고 이것을 실행하면 서버에서 다음 예외가 표시됩니다.
15:26:35 DEBUG [org.jboss.resteasy.resteasy_jaxrs.i18n] RESTEASY002305: Failed executing POST /profile: javax.ws.rs.NotSupportedException: RESTEASY003065: Cannot consume content type
at org.jboss.resteasy.core.registry.SegmentNode.match(SegmentNode.java:453)
at org.jboss.resteasy.core.registry.SegmentNode.match(SegmentNode.java:155)
at org.jboss.resteasy.core.registry.RootNode.match(RootNode.java:58)
at org.jboss.resteasy.core.registry.RootClassNode.match(RootClassNode.java:47)
at org.jboss.resteasy.core.ResourceMethodRegistry.getResourceInvoker(ResourceMethodRegistry.java:482)
at org.jboss.resteasy.core.SynchronousDispatcher.getInvoker(SynchronousDispatcher.java:323)
at org.jboss.resteasy.core.SynchronousDispatcher.lambda$invoke$4(SynchronousDispatcher.java:244)
at org.jboss.resteasy.core.SynchronousDispatcher.lambda$preprocess$0(SynchronousDispatcher.java:153)
at org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:363)
at org.jboss.resteasy.core.SynchronousDispatcher.preprocess(SynchronousDispatcher.java:156)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:238)
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:249)
at io.quarkus.resteasy.runtime.ResteasyFilter.doFilter(ResteasyFilter.java:30)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:63)
at io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68)
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:133)
at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:65)
at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:270)
at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:59)
at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:116)
at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:113)
at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
at io.quarkus.undertow.runtime.UndertowDeploymentRecorder$9$1$1.call(UndertowDeploymentRecorder.java:476)
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:250)
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:59)
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:82)
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:290)
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:669)
at io.quarkus.runtime.CleanableExecutor$CleaningRunnable.run(CleanableExecutor.java:224)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:2011)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1535)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1395)
at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
at java.base/java.lang.Thread.run(Thread.java:830)
at org.jboss.threads.JBossThread.run(JBossThread.java:479)
내가 뭔가를 놓치고 있습니까? Quarkus 사이트에서 multipart 를 사용 하여 REST 클라이언트 를 만드는 문서를 찾았 지만 서버 측 리소스 에 대한 문서는 없습니다. 이 작업을 수행하기 위해해야 할 일이 더 있습니까?
문제는
@FormParam("profileImage")
@PartType(MediaType.APPLICATION_OCTET_STREAM)
private byte[] profileImage = null;
이 부분에 대해 허용하는 유일한 콘텐츠 유형이라고 광고하고 application/octet-stream
있습니다. 그러나 당신은 이미지를 보내고 있으며 cURL은 이미지의 콘텐츠 유형을 설정하지 않습니다. 나는 후드 아래에서 그것을로 설정한다고 상상할 것 image/jpg
입니다. 수동으로 유형을 설정할 수 있습니다 (그리고 그 해결됩니다 이 요청)
profileImage=@profile_image.jpg;type=application/octet-stream
하지만 개인적으로 @PartType
. 필드 유형이 이미 byte[]
이므로 변환에 문제가 없습니다. 또한 많은 클라이언트가 개별 부품의 콘텐츠 유형을 설정할 수 없습니다. 브라우저 / JS 클라이언트와 마찬가지로 cURL과 마찬가지로 기본적으로 파일의 콘텐츠 유형을 설정합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다