Lasso Soft Inc. > Home

[ file_serve ]

Method

[File_Serve] is a compatibility layer implementation of [web_response->sendFile].

The [File_Serve] method serves a file which is stored in a variable in place of the current Lasso response. The name of the file can be specified and, in supported browsers, the file will be written to disk using that name and/or displayed in the browser.

The [File_Serve] method can be used to serve image files, multimedia files, file archives, or even HTML files.

None of the contents of the current response will be served. [File_Serve] completely rewrites the HTTP headers and contents of the served response. [File_Serve] also performs an [Abort] so no code after [File_Serve] will be executed.

The first parameter to the method should be a variable which contains the file to be served. An optional -File parameter allows the name of the file to be specified. An optional -Type parameter allows the MIME type of the served file (default 'text/html') to be overridden.

Possible MIME types include:

  • text/html - HTML text
  • image/jpeg - JPEG graphic file
  • image/gif - GIF graphic file
  • image/png - PNG graphic file
  • text/xml - XML data
  • application/pdf - Portable Document Format file
  • Syntax
file_serve(
	content_bytes,
	-file,
	-type='type',
	-charset='charset',
	-disposition='attachment'
)


File_Serve('File Data')
 
File_Serve('File Data', -File='Example.html')
 
File_Serve('Image Data', -File='Example.gif', -Type='image/gif')

local(myFile = Include_Raw('Example.jpg'))
File_Serve(#myFile, -File='Example.jpg', -Type='image/jpeg')
Examples

No examples found

Recent Comments

When trying to serve a file as a base64-encoded string, be sure to explicitly set -file="..." in your code. Whereas in Lasso 8.5, file_serve would work without setting a filename explicitly, Lasso 9 will fail with a cryptic error message without a filename being set.

Posted on: 02 December 2013

Please note that periodically LassoSoft will go through the notes and may incorporate information from them into the documentation. Any submission here gives LassoSoft a non-exclusive license and will be made available in various formats to the Lasso community.

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2014 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft