-
Notifications
You must be signed in to change notification settings - Fork 46
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
Response::withFile() and Response::withFileDownload() #91
Conversation
In Firefox 67.0 (64-Bit) the file name in the "Save as" dialog would be wrong if we use If instead we write $disposition .= '; filename*=UTF-8\'\'' . urlencode($fileName); then all the browsers mentioned above display the correct file name. See http://test.greenbytes.de/tech/tc2231/#encoding-2231-char for more information. Note that this works only, if the |
If we pass a public function __invoke(ServerRequest $request, Response $response, array $args = []): Response
$stream = $psr17Factory->createStreamFromFile('data.json');
return $response->withFileDownload($stream);
} Chrome and Opera defaults to the filename Probably we should raise an exception if a user tries to do that? Or is that the responsibility of a user? |
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition |
Of course, if the url contains a path from which the user agent can parse the filename, then this is okay. But obviously, if the download would be triggered by calling By the way, the same holds for any paths ending with a slash (of course that should be avoided). So if we define a route $app->get('/hello/', function (\Slim\Http\ServerRequest $request, \Slim\Http\Response $response, array $args) {
$psr17Factory = new Psr17Factory();
$stream = $psr17Factory->createStream('1234');
return $response->withFileDownload($stream);
}); then a request to So I guess this is a problem that the user agents should solve for themselves. It is not our duty to prevent that, right? |
I think this is not our problem. But we can also set default filename to "Download" (don't throw error) |
Let's not throw an error but append a default filename as suggested like "download" or "attachment" when a |
Would it make sense to try to get the file name from the metadata |
Yea for sure why not. |
Resuming to adopt the proposed direction in #88
New Response Methods:
Behavior
The
$file
parameter can be astring
which points to a file, an existingresource
handle or aStreamInterface
as proposed by @roxblnfkThe
$name
parameter overrides the defaultattachment
value for theContent-Disposition
header. The given$name
is filtered throughurlencode()
to ensure it is a valid header value.The
$contentType
parameter accepts astring
to override theContent-Type
header to a user defined value. Defaults totrue
which attempts to detect the mime type viamime_content_type()
and falls back toapplication/octet-stream
otherwise. If set tofalse
theContent-Type
header is not appended at all.Closes #82