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
@GET
@Path("download/{fileId}")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Uni<Response> downloadFile(@PathParam("fileId") BigInteger id) {
try {
return downloadService.download(id);
} catch (Exception e) {
LOG.error("Failed to download file. Exception: ", e);
throw new FileInformationNotFoundException(id);
}
}
// Inside public class FileDownloadService
public Uni<Response> download(BigInteger archiveId) {
// Simplified version
String testPath = "path/to/file";
final OpenOptions openOptions = new OpenOptions().setCreate(false).setWrite(false).setCreate(false);
return vertx.fileSystem().open(testPath, openOptions)
.onItem()
.transform(asyncFile -> Response.ok(asyncFile, "image/png")
.header("X-Content-Type", "image/png") // Just another test for a
.header("Content-Disposition", "attachment;filename=\"JustATest.txt\"")
.build());
// This should be the actual code
/* return repo.findById(archiveId)
.onItem()
.ifNull()
.failWith(new FileInformationNotFoundException(archiveId))
.flatMap(info -> {
final OpenOptions openOptions = new OpenOptions().setCreate(false).setWrite(false).setCreate(false);
return vertx.fileSystem().open(info.path, openOptions);
})
.onItem()
.transform(asyncFile -> Response.ok(asyncFile, "image/png")
.header("X-Content-Type", "image/png") // Here the actual media type stored in the db should go
.header("Content-Disposition", "attachment;filename=\"JustATest.txt\"")
.build()
);*/
}
Sadly I always get a response of:
Returning an AsyncFile is not supported with WriterInterceptors","stack":"java.lang.UnsupportedOperationException: Returning an AsyncFile is not supported with WriterInterceptors
I found the error message in the quarkus source code, but I am not sure what I am doing wrong or how I can mitigate it.
Also I can't seem to overwrite the content-type header at all... it's always: "content-type: application/json; charset=utf-8"... this can be mitigated on the client side, but with a lot of effort :/
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
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone!
Edit: So, the root cause for the following problem is:
io.quarkus quarkus-smallrye-opentracingWhen I disable this dependency, everything works like a charm.
The problem is, I need to use opentracing sighs, so I currently face a situation of mutual exclusive feature-requests
Original post below
First of, let me say: Thanks for all the effort going into this project!
I am using Quarkus 2.10.3.Final
Overall goal:
Allow downloading potentially huge files as a stream, to mitigate need to allocate a lot of memory
Solution that worked:
New requirement:
Add custom header to response and also set "Content-Type"-Header.
I found https://stackoverflow.com/a/72524030
So I tried it like this:
// Inside FileController
// Inside public class FileDownloadService
Sadly I always get a response of:
I found the error message in the quarkus source code, but I am not sure what I am doing wrong or how I can mitigate it.
Also I can't seem to overwrite the content-type header at all... it's always: "content-type: application/json; charset=utf-8"... this can be mitigated on the client side, but with a lot of effort :/
Beta Was this translation helpful? Give feedback.
All reactions