NAME
Kernel::WebApp::Controller::API::Role::ServesFileResource – Serves file.
PUBLIC INTERFACE
Consume this role to have a method at disposal to serve a file resource as a response:
with qw(
Kernel::WebApp::Controller::API::Role::ServesFileResource
)
The role will provide you with a ready to use ServeFileResource() method for serving file contents. If file contents is not passed, it will return a 404 Not Found
response.
You can still provide your own or wrap around ServeFileResource()
method to implement a different logic and checks behind it.
ServeFileResource()
This method returns a file resource to the requester, based on specified content. Just pass back its return value which will be a valid response.
return $Self->ServeFileResource(
Content => $Content, # (optional) Returns 404 error if missing
Filename => 'myfile.txt', # (optional) default: 'unknown'
ContentType => 'text/plain', # (optional) default: 'application/octet-stream'
ContentDisposition => 'attachment', # (optional) default: 'inline'
);