-
Notifications
You must be signed in to change notification settings - Fork 295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug: UploadScalar is not working when i work generateCodegen #1345
Comments
Zoe0631
changed the title
bug:
bug: UploadScalar is not working when i work generateCodegen
Nov 30, 2022
Prefacing this with I'm not sure if this is the "correct" way to do this, but we use the something like the following code which works for getting multipart files: @DgsMutation
public List<Response> upload(@InputArgument final List<Part> parts, final DataFetchingEnvironment env) {
final List<MultipartFile> attachmentParts = env.getArgument("files");
final List<Response> responses = new ArrayList<>();
for (int x = 0; x < attachmentParts.size(); x++) {
final MultipartFile part = attachmentParts.get(x);
Path path = null;
try {
final String tmpdir = System.getProperty(TEMP_FILE_PATH);
final String name = UUID.randomUUID().toString();
path = Paths.get(tmpdir, FilenameUtils.getName(TEMP_FILE_PREFIX + name + TEMP_FILE_EXTENSION));
Files.copy(inputStream, path);
final Response response = facade.uploadFile(path.toFile(), part.getOriginalFilename());
responses.add(response);
} catch (final IOException e) {
log.error("Cannot process file", e);
} finally {
try {
if (path != null) {
Files.delete(path);
}
} catch (final IOException e) {
log.error("Unable to delete the file for the following reason: {}", e.getMessage(), e);
}
}
}
return responses;
} I'm not sure if parts parameter is actually needed to be honest. I've cut some of the code so it's generic but hopefully it should work for you (can also probably clean it up). |
You can extract the argument as a MultipartFile as shown here:
```
@DgsData(parentType = DgsConstants.MUTATION.TYPE_NAME, field =
"uploadScriptWithMultipartPOST")
public boolean uploadScript(DataFetchingEnvironment dfe) throws IOException {
// NOTE: Cannot use @InputArgument or Object Mapper to convert to
class, because MultipartFile cannot be
// deserialized
MultipartFile file = dfe.getArgument("input");
String content = new String(file.getBytes());
return ! content.isEmpty();
}
```
https://netflix.github.io/dgs/advanced/file-uploads/#multipart-file-upload
…On Wed, Nov 30, 2022 at 2:46 AM Ancient-Dragon ***@***.***> wrote:
Prefacing this with I'm not sure if this is the "correct" way to do this,
but we use the something like the following code which works for getting
multipart files:
@DgsMutation
public List<Response> ***@***.*** final List<Part> parts, final DataFetchingEnvironment env) {
final List<MultipartFile> attachmentParts = env.getArgument("files");
final List<Response> responses = new ArrayList<>();
for (int x = 0; x < attachmentParts.size(); x++) {
final MultipartFile part = attachmentParts.get(x);
Path path = null;
try {
final String tmpdir = System.getProperty(TEMP_FILE_PATH);
final String name = UUID.randomUUID().toString();
path = Paths.get(tmpdir, FilenameUtils.getName(TEMP_FILE_PREFIX + name + TEMP_FILE_EXTENSION));
Files.copy(inputStream, path);
final Response response = facade.uploadFile(path.toFile(), part.getOriginalFilename());
responses.add(response);
} catch (final IOException e) {
log.error("Cannot process file", e);
} finally {
try {
if (path != null) {
Files.delete(path);
}
} catch (final IOException e) {
log.error("Unable to delete the file for the following reason: {}", e.getMessage(), e);
}
}
}
return responses;
}
I'm not sure if parts parameter is actually needed to be honest. I've cut
some of the code so it's generic but hopefully it should work for you (can
also probably clean it up).
—
Reply to this email directly, view it on GitHub
<#1345 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AJ5JPXMNSZ5ZDAA2O3XBVALWK4V7XANCNFSM6AAAAAASPNDBAQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please read our contributor guide before
creating an issue.
In my opinion, the issue is not a common situation.
Expected behavior
According to the guide, if I only declare 'scalar Upload', isn't Upload created?
Actual behavior
dependency(build.gradle.kts)
implementation(platform("com.netflix.graphql.dgs:graphql-dgs-platform-dependencies:5.1.1"))
implementation("com.netflix.graphql.dgs:graphql-dgs-spring-boot-starter")
Upload Scalar built into the dgs framework
what should i do for using Upload scalar that is for access multipart/ form- data?
The text was updated successfully, but these errors were encountered: