download function

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

download function

johnd
I have done some reading about http downloads.  One way is to set a
header like Content-Disposition.

I would like my download to not be under the websever's root for
security reasons.  I'd have an rpc call that authenticates the user
then returns the data to my qooxdoo app.  I tried a window.open using
the data uri scheme...  This is the code I use:

  downloadBtn.addListener("execute", function(e) {
        var path=getPath(ctx.tree);

        var handler = function(result, ex){
                if (ex ==  null) {

window.open("data:application/octet-stream;base64,"+result[1],'Download');
                } else {
                        ctx.debug("exception: "+ex);
                }
        };
        ctx.rpc.callAsync(handler,"getFile",
'run-'+ctx.run_id+path+'/'+
ctx.tree.getSelection()[0].getLabel(),true);



      }, this)

result[1] is base64 encoded and when this code runs it works on
firefox, but doesn't allow the user or me on the dev side to set the
name of the file.  It saves the file as a name that looks like base64
and isn't very pretty.


any ideas on how I can have my qooxdoo app allow a user to be prompted
to save a stream of data?

------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: download function

johnd
On Thu, Sep 22, 2011 at 3:51 PM, John de la Garza <[hidden email]> wrote:
> I have done some reading about http downloads.  One way is to set a
> header like Content-Disposition.
>
> I would like my download to not be under the websever's root for
> security reasons.  I'd have an rpc call that authenticates the user
> then returns the data to my qooxdoo app.  I tried a window.open using
> the data uri scheme..


If anyone is interested, I have moved away from a rpc call to return
an array for a data://uri due to the length limitations

I just have a stand alone cgi program that authenticates then returns the file
with these headers:

Content-Type:application/x-download\nContent-Disposition:attachment

I call a window.open() in my client and it pops open a box to download
or open and I also set thename in the header so it all looks good.

------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2dcopy2
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: download function

slah
Hello,
I'm about to implement such function in my project.
It will be great if you can share your experience.

Thank you.
Reply | Threaded
Open this post in threaded view
|

Re: download function

johnd
On Sat, Sep 24, 2011 at 3:03 AM, slah <[hidden email]> wrote:
> Hello,
> I'm about to implement such function in my project.
> It will be great if you can share your experience.
>

Would you need to use authentication?

I am working on a download process that requires auth

so I have a cgi (that will take credentials) return the file

here is my sample code (I don't have the auth done, it will just
passed as a url parameter for my first try)

#!/usr/bin/python



import cgitb
import sys
import cgi
import os
import platform
from enfdata import Common

cgitb.enable()


def download():
    """
    Returns the demo file
    """
    form = cgi.FieldStorage()
    path = form['path'].value
    mainDir=Common.EnFuzionCommand("cluster get ENFMAIN_DIRECTORY").strip()
    FILENAME = mainDir+'/'+path
    sys.stderr.write('Filename: '+FILENAME)
    file = open(FILENAME, 'rb')
    buff = file.read()
    print "Content-Type:image\nContent-Disposition:attachment;filename=%s\nContent-Length:%s\n"
%    (os.path.split(FILENAME)[-1], len(buff))
    if sys.platform.find("win32") == 0:
        import msvcrt
        msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
    print buff
download()

------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel