You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
mutation {
createFile(input: InputObject, file: Upload): Long
}
My MutationMapping code is as below:
@MutationMapping
public Long createFile(@argument("input") InputObject in, @argument("file") MultipartFile file) {
if (file == null || file.isEmpty()) {
throw new RuntimeException("File is null or empty!");
}
System.out.println("Received file: " + file.getOriginalFilename() + " (size: " + file.getSize() + " bytes)");
return facade.createFile(in, file);
}
Have a custom scalar Upload code:
public static final GraphQLScalarType UPLOAD = GraphQLScalarType.newScalar()
.name("MultiPartFile")
.description("A custom scalar for handling file uploads with MultipartFile")
.coercing(new Coercing<MultipartFile, MultipartFile>() { @OverRide
public MultipartFile serialize(Object dataFetcherResult) {
if (dataFetcherResult instanceof MultipartFile file) {
return file;
}
throw new IllegalArgumentException("Unable to serialize object to MultipartFile");
} @OverRide
public MultipartFile parseValue(Object input) {
if (input instanceof MultipartFile file) {
return file;
}
throw new IllegalArgumentException("Unable to parse input to MultipartFile");
} @OverRide
public MultipartFile parseLiteral(Object input) {
throw new UnsupportedOperationException("Parsing literal is not supported for MultipartFile");
}
})
.build();
I don't have anything specific set on my application properties file regarding file upload.
My postman request looks like this to test this API:
However my API itself does not get called, and on postman I get
Error : 415 Unsupported Media Type
on server-side, I get this error:
2025-02-16 00:02:56,731|INFO | |http-nio-8089-exec-2|org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/]|Initializing Spring DispatcherServlet 'dispatcherServlet'
2025-02-16 00:02:56,820|INFO | |http-nio-8089-exec-2|org.apache.coyote.http11.Http11Processor|Error parsing HTTP request header
Note: further occurrences of HTTP request parsing errors will be logged at DEBUG level.
java.lang.IllegalArgumentException: Invalid character found in method name [----------------------------2776250514545923995196340x0d0x0aContent-Disposition: ]. HTTP method names must be tokens
at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:406)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:270)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:905)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1741)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1190)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:63)
at java.base/java.lang.Thread.run(Thread.java:1583)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I use sprint boot 3.4.0 and JDK 21.
my GraphQL API schema looks like below
scalar upload
mutation {
createFile(input: InputObject, file: Upload): Long
}
My MutationMapping code is as below:
@MutationMapping
public Long createFile(@argument("input") InputObject in,
@argument("file") MultipartFile file) {
if (file == null || file.isEmpty()) {
throw new RuntimeException("File is null or empty!");
}
System.out.println("Received file: " + file.getOriginalFilename() + " (size: " + file.getSize() + " bytes)");
return facade.createFile(in, file);
}
Have a custom scalar Upload code:
public static final GraphQLScalarType UPLOAD = GraphQLScalarType.newScalar()
.name("MultiPartFile")
.description("A custom scalar for handling file uploads with MultipartFile")
.coercing(new Coercing<MultipartFile, MultipartFile>() {
@OverRide
public MultipartFile serialize(Object dataFetcherResult) {
if (dataFetcherResult instanceof MultipartFile file) {
return file;
}
throw new IllegalArgumentException("Unable to serialize object to MultipartFile");
}
@OverRide
public MultipartFile parseValue(Object input) {
if (input instanceof MultipartFile file) {
return file;
}
throw new IllegalArgumentException("Unable to parse input to MultipartFile");
}
@OverRide
public MultipartFile parseLiteral(Object input) {
throw new UnsupportedOperationException("Parsing literal is not supported for MultipartFile");
}
})
.build();
I don't have anything specific set on my application properties file regarding file upload.
My postman request looks like this to test this API:
However my API itself does not get called, and on postman I get
Error : 415 Unsupported Media Type
on server-side, I get this error:
2025-02-16 00:02:56,731|INFO | |http-nio-8089-exec-2|org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/]|Initializing Spring DispatcherServlet 'dispatcherServlet'
2025-02-16 00:02:56,820|INFO | |http-nio-8089-exec-2|org.apache.coyote.http11.Http11Processor|Error parsing HTTP request header
Note: further occurrences of HTTP request parsing errors will be logged at DEBUG level.
java.lang.IllegalArgumentException: Invalid character found in method name [----------------------------2776250514545923995196340x0d0x0aContent-Disposition: ]. HTTP method names must be tokens
at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:406)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:270)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:905)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1741)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1190)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:63)
at java.base/java.lang.Thread.run(Thread.java:1583)
Beta Was this translation helpful? Give feedback.
All reactions