Download SimpleFile

Dear Nextclouds-Devs,

is there a way to force the browser to download a SimpleFile via a Controller response?

I tried the DownloadResponse, StreamResponse, FileDisplayResponse and good old DataResponse with some JavaScript โ€“ but failed miserably. The file is stored in the AppData SimpleFileSystem. So far so good, but I would like to download it directly.

Any hint in the right direction would help a lot :slight_smile:

Thanks in advance :slightly_smiling_face:

The issue is mainly that the ISimpleFile abstraction doesnโ€™t provide all information that is needed by the Response classes to properly handle the display/download. You can work around that by fetching the file from the root folder. You can find an example over here:

Thanks for your help! Unfortunately I only get something like this as response in the Javascript console and there is no prompt for a download. The file is a correctly created zip, I checked via ftp. Do you have another idea for that pink mess? :upside_down_face:

How do you submit the request to the download endpoint? It seems that it is a XHR request so the currently opened site gets the response data instead of the browser to handle the download.

:man_facepalming: just when I thought Iโ€™m done with this sort of unnecessary mistakesโ€ฆ
Thank you :slightly_smiling_face:

Oh regarding the initial problem: I found that she SimpleFile Class seems to have a method โ€˜readโ€™ which does the fopen(โ€˜rโ€™) on the $file property. So this seems to work for me without the workaround:
$response = new StreamResponse($zipFile->read());

Ah indeed, I even implemented that a while ago :see_no_evil: Sorry, I was a bit confused by the fallback in the deck app then. Good to hear that it works now.