> Is there any other way to stream files?

ServletResponse.getOutputStream().write()

Am Mi., 10. Juli 2024 um 18:21 Uhr schrieb Ulf Dittmer
<ulf.ditt...@googlemail.com.invalid>:
>
> How would I implement to stream a file that is not a page attachment? I'm
> implementing an image upload and retrieval facility, and need to display a
> link to an image that is stored on disk.
>
> I thought DynamicAttachment might be the way to go, but I can neither get
> it create the correct link (creates something like "/attach/fileName", with
> "fileName" being the one I supplied when creating the dynamic attachment)
> which results in a 404.
>
> DynamicAttachment dynAtt = new DynamicAttachment(context.getEngine(),
> context.getPage().getName(), fileName, uploadProvider);
> dynAtt.setCacheable(false);
> dynAtt.setLastModified(context.getPage().getLastModified());
> AttachmentManager attMgr =
> context.getEngine().getManager(AttachmentManager.class);
> attMgr.storeDynamicAttachment(context, dynAtt);
>
> where the uploadProvider does nothing more than
>
> public InputStream getAttachmentData (Context context, Attachment att)
> throws ProviderException, IOException {
>     Path filePath = Paths.get(uploadDir, att.getFileName());
>     return Files.newInputStream(filePath);
> }
>
> But anyway, dynamic attachments do not seem to get stored, making the
> entire scheme unworkable.
>
> Is there any other way to stream files?
>
> Thanks
> Ulf

Reply via email to