[Kepler] Using Orbit to start a download

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

[Kepler] Using Orbit to start a download

RJP Computing
Since LuaForge is down I hope it is ok for me to ask Kepler and Orbit questions here.

Hi,

I am using Orbit in an application and I want to create a URL map to download files, like this "http://somesite.com/download/filename.zip". How do I make the browser think that it is time to download the file. I Googled and found a PHP article where it was using header(). How can I do this in Orbit. Thanks.
--
Regards,
Ryan
Reply | Threaded
Open this post in threaded view
|

Re: [Kepler] Using Orbit to start a download

Fabio Mascarenhas
Hi RJP,

You can use the serve_static method of your application object to send
a file to the client. It sets the content-type based on the extension
of the file you are sending. The syntax is

orbit_app:serve_static(web, path_to_file)

It returns the contents of the file, so just tail-call it in your
handler. serve_static also supports X-SendFile, if you set
use_xsendfile to true in your application object.

--
Fabio Mascarenhas, Lablua
http://www.lua.inf.puc-rio.br




On Thu, Oct 8, 2009 at 11:36 AM, RJP Computing <[hidden email]> wrote:

> Since LuaForge is down I hope it is ok for me to ask Kepler and Orbit
> questions here.
>
> Hi,
>
> I am using Orbit in an application and I want to create a URL map to
> download files, like this "http://somesite.com/download/filename.zip". How
> do I make the browser think that it is time to download the file. I Googled
> and found a PHP article where it was using header(). How can I do this in
> Orbit. Thanks.
> --
> Regards,
> Ryan
>
Reply | Threaded
Open this post in threaded view
|

Re: [Kepler] Using Orbit to start a download

RJP Computing
Hi Fabio,

On Thu, Oct 8, 2009 at 10:41 AM, Fabio Mascarenhas <[hidden email]> wrote:
Hi RJP,

You can use the serve_static method of your application object to send
a file to the client. It sets the content-type based on the extension
of the file you are sending. The syntax is

orbit_app:serve_static(web, path_to_file)

It returns the contents of the file, so just tail-call it in your
handler.

This is probably a stupid question, but what does it mean to tail-call it?
 
serve_static also supports X-SendFile, if you set
use_xsendfile to true in your application object.

What are the reasons to use X-SendFile versus the default?
--
Regards,
Ryan
Reply | Threaded
Open this post in threaded view
|

Re: [Kepler] Using Orbit to start a download

Yuri Takhteyev
> This is probably a stupid question, but what does it mean to tail-call it?

http://www.lua.org/pil/6.3.html

- yuri
Reply | Threaded
Open this post in threaded view
|

Re: [Kepler] Using Orbit to start a download

RJP Computing
Yuri,

On Thu, Oct 8, 2009 at 11:25 AM, Yuri Takhteyev <[hidden email]> wrote:
> This is probably a stupid question, but what does it mean to tail-call it?

http://www.lua.org/pil/6.3.html

Got it thanks.
--
Regards,
Ryan
Reply | Threaded
Open this post in threaded view
|

Re: [Kepler] Using Orbit to start a download

RJP Computing
In reply to this post by RJP Computing
Hi Fabio,

On Thu, Oct 8, 2009 at 10:20 AM, RJP Computing <[hidden email]> wrote:
 serve_static also supports X-SendFile, if you set use_xsendfile to true in your application object.

What are the reasons to use X-SendFile versus the default? I try that and I get a page that has the html source:

    <html><head><title>Not Found</title></head>
    <body><p>Not found!</p></body></html>

and no download it started. When I set 'use_xsendfile = false' I get the text.txt file rendered in the browser. Is this what is suppose to happen?

Is there a way to force a download dialog to open instead of rendering the text in the browser?
--
Regards,
Ryan
Reply | Threaded
Open this post in threaded view
|

Re: [Kepler] Using Orbit to start a download

Fabio Mascarenhas
On Mon, Mar 1, 2010 at 11:03 AM, RJP Computing <[hidden email]> wrote:
Hi Fabio,


On Thu, Oct 8, 2009 at 10:20 AM, RJP Computing <[hidden email]> wrote:
 serve_static also supports X-SendFile, if you set use_xsendfile to true in your application object.

What are the reasons to use X-SendFile versus the default? I try that and I get a page that has the html source:

    <html><head><title>Not Found</title></head>
    <body><p>Not found!</p></body></html>

and no download it started. When I set 'use_xsendfile = false' I get the text.txt file rendered in the browser. Is this what is suppose to happen?


X-Sendfile is a header that some servers support that tells the server to send the file for you. You have to check if your web server supports X-Sendfile and how to enable it.
 
Is there a way to force a download dialog to open instead of rendering the text in the browser?

That is up to the browser and what it decides to do with the file's content-type...
 
--
Regards,
Ryan

--
Fabio Mascarenhas

Reply | Threaded
Open this post in threaded view
|

Re: [Kepler] Using Orbit to start a download

Ryan Pusztai
Hi Fabio,

On Mon, Mar 1, 2010 at 9:24 AM, Fabio Mascarenhas <[hidden email]> wrote:
X-Sendfile is a header that some servers support that tells the server to send the file for you. You have to check if your web server supports X-Sendfile and how to enable it.

OK I don't think I need this, and it is Xavante that I am using to test this functionality. But I release the software using Apache 2.x. I will look into it if I can't get the default to work.
  
Is there a way to force a download dialog to open instead of rendering the text in the browser?

That is up to the browser and what it decides to do with the file's content-type...

OK thanks for the explanation.
--
Regards,
Ryan
Reply | Threaded
Open this post in threaded view
|

Re: [Kepler] Using Orbit to start a download

Michal Kottman

>        
>         That is up to the browser and what it decides to do with the
>         file's content-type...
>
> OK thanks for the explanation.

You can set the Content-disposition header in order to force the browser
to download the file [1].

The header should look like this:

Content-disposition: attachment; filename=file.txt

In Orbit, this code should do the trick:

function send(web)
  web.headers['Content-disposition'] = 'attachment; filename=file.txt'
  web.headers['Content-type'] = 'text/plain'
  ...
end

Notice that you should also set the MIME type, otherwise the browser
thinks that you are sending a webpage.

[1] http://www.boutell.com/newfaq/creating/forcedownload.html

Reply | Threaded
Open this post in threaded view
|

Re: [Kepler] Using Orbit to start a download

Ryan Pusztai
Hi Michal,

On Mon, Mar 1, 2010 at 11:28 AM, Michal Kottman <[hidden email]> wrote:
You can set the Content-disposition header in order to force the browser
to download the file [1].

The header should look like this:

Content-disposition: attachment; filename=file.txt

In Orbit, this code should do the trick:

function send(web)
 web.headers['Content-disposition'] = 'attachment; filename=file.txt'
 web.headers['Content-type'] = 'text/plain'
 ...
end

Notice that you should also set the MIME type, otherwise the browser
thinks that you are sending a webpage.

[1] http://www.boutell.com/newfaq/creating/forcedownload.html


Tested and this works great! Thanks. 
--
Regards,
Ryan