[OFFish] Serving Downloads - Link on AJAX page

View: New views
6 Messages — Rating Filter:   Alert me  

[OFFish] Serving Downloads - Link on AJAX page

by B. Perkins :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm working on a AJAX page that is using a Flash based uploader for
jQuery (Uploadify, it is nice and worth a look).

When I successfully upload a document, the uploaded file details are
inserted into an area on the current page via DOM manipulation. The
details contain a link to the script that will serve the file. The link
is not a URL to a file on disk. The script reads a file designated in
the query params and serves the output.

I have something working but the interaction is not ideal. The problems are:
(1) Clicking the link takes the user away from the page where the link
appears.
(2) Problem 1 was partially solved by putting a target="_blank" which
opens a new window. that it better, but still isn't ideal.

What I would really like is to not disrupt or move away from the parent
page, and force the appearance of the standard Open dialog with either
the "Save As" or "Open With" options. In other words force the file to
be downloaded and not displayed in the browser (unless they choose Open
With <favorite browser).

Has anyone done this before? Is it simply a matter of setting the right
headers and streaming the content?

Thanks,

Brad Perkins
_______________________________________________
Active4D-dev mailing list
Active4D-dev@...
http://mailman.aparajitaworld.com/mailman/listinfo/active4d-dev
Archives: http://mailman.aparajitaworld.com/archive/active4d-dev/

Re: [OFFish] Serving Downloads - Link on AJAX page

by RandyJaynes :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Brad,

Maybe you could target an inline frame that then manipulates the DOM  
of its parent?

The inline frame could be the one that throws up the open dialog and  
all the other stuff related to getting the file.

It could be 1 pixel by 1 pixel and not even be noticed.

HTH,
Randy

On Aug 3, 2009, at 6:55 PM, Brad Perkins wrote:

> I'm working on a AJAX page that is using a Flash based uploader for
> jQuery (Uploadify, it is nice and worth a look).
>
> When I successfully upload a document, the uploaded file details are
> inserted into an area on the current page via DOM manipulation. The
> details contain a link to the script that will serve the file. The  
> link
> is not a URL to a file on disk. The script reads a file designated in
> the query params and serves the output.
>
> I have something working but the interaction is not ideal. The  
> problems are:
> (1) Clicking the link takes the user away from the page where the link
> appears.
> (2) Problem 1 was partially solved by putting a target="_blank" which
> opens a new window. that it better, but still isn't ideal.
>
> What I would really like is to not disrupt or move away from the  
> parent
> page, and force the appearance of the standard Open dialog with either
> the "Save As" or "Open With" options. In other words force the file to
> be downloaded and not displayed in the browser (unless they choose  
> Open
> With <favorite browser).
>
> Has anyone done this before? Is it simply a matter of setting the  
> right
> headers and streaming the content?

_______________________________________________
Active4D-dev mailing list
Active4D-dev@...
http://mailman.aparajitaworld.com/mailman/listinfo/active4d-dev
Archives: http://mailman.aparajitaworld.com/archive/active4d-dev/

Re: [OFFish] Serving Downloads - Link on AJAX page

by B. Perkins :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I did some reading last night and an iframe strategy appears to be the way
to go. I need to figure out which headers to set to force the files to
download and not serve.

Thanks,

Brad

> Brad,
>
> Maybe you could target an inline frame that then manipulates the DOM
> of its parent?
>
> The inline frame could be the one that throws up the open dialog and
> all the other stuff related to getting the file.
>
> It could be 1 pixel by 1 pixel and not even be noticed.
>
> HTH,
> Randy
>
> On Aug 3, 2009, at 6:55 PM, Brad Perkins wrote:
>
>> I'm working on a AJAX page that is using a Flash based uploader for
>> jQuery (Uploadify, it is nice and worth a look).
>>
>> When I successfully upload a document, the uploaded file details are
>> inserted into an area on the current page via DOM manipulation. The
>> details contain a link to the script that will serve the file. The
>> link
>> is not a URL to a file on disk. The script reads a file designated in
>> the query params and serves the output.
>>
>> I have something working but the interaction is not ideal. The
>> problems are:
>> (1) Clicking the link takes the user away from the page where the link
>> appears.
>> (2) Problem 1 was partially solved by putting a target="_blank" which
>> opens a new window. that it better, but still isn't ideal.
>>
>> What I would really like is to not disrupt or move away from the
>> parent
>> page, and force the appearance of the standard Open dialog with either
>> the "Save As" or "Open With" options. In other words force the file to
>> be downloaded and not displayed in the browser (unless they choose
>> Open
>> With <favorite browser).
>>
>> Has anyone done this before? Is it simply a matter of setting the
>> right
>> headers and streaming the content?
>
> _______________________________________________
> Active4D-dev mailing list
> Active4D-dev@...
> http://mailman.aparajitaworld.com/mailman/listinfo/active4d-dev
> Archives: http://mailman.aparajitaworld.com/archive/active4d-dev/
>

_______________________________________________
Active4D-dev mailing list
Active4D-dev@...
http://mailman.aparajitaworld.com/mailman/listinfo/active4d-dev
Archives: http://mailman.aparajitaworld.com/archive/active4d-dev/

Re: [OFFish] Serving Downloads - Link on AJAX page

by CDonahue :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Brad,

> I need to figure out which headers to set to force the files to
> download and not serve.

We use something like:

<%
        set cache control("private")
        set response
header("content-disposition";"attachment;filename="+ $documentName)
%>

I think we also make sure that $documentName doesn't contain any spaces
or other "non-document" characters. Some browsers will choke if the
"filename" has whitespace in it.

Best Regards,
- Clayton
_______________________________________________
Active4D-dev mailing list
Active4D-dev@...
http://mailman.aparajitaworld.com/mailman/listinfo/active4d-dev
Archives: http://mailman.aparajitaworld.com/archive/active4d-dev/

Re: [OFFish] Serving Downloads - Link on AJAX page

by B. Perkins :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> Hi Brad,
>
>> I need to figure out which headers to set to force the files to
>> download and not serve.
>
> We use something like:
>
> <%
> set cache control("private")
> set response
> header("content-disposition";"attachment;filename="+ $documentName)
> %>
>
> I think we also make sure that $documentName doesn't contain any spaces
> or other "non-document" characters. Some browsers will choke if the
> "filename" has whitespace in it.

Thanks for the whitespace tip. In order to prevent overwrites due to
potential file name collisions, I'm storing the filename as an
MD5(timestamp + random).ext, but would like to serve the file back with
the original name, or something close. Have you tried to URL encode the
whitespace or do you strip it out or replace with underscores?

Best,

Brad

>
> Best Regards,
> - Clayton
> _______________________________________________
> Active4D-dev mailing list
> Active4D-dev@...
> http://mailman.aparajitaworld.com/mailman/listinfo/active4d-dev
> Archives: http://mailman.aparajitaworld.com/archive/active4d-dev/
>

_______________________________________________
Active4D-dev mailing list
Active4D-dev@...
http://mailman.aparajitaworld.com/mailman/listinfo/active4d-dev
Archives: http://mailman.aparajitaworld.com/archive/active4d-dev/

Re: [OFFish] Serving Downloads - Link on AJAX page

by CDonahue :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I haven't tried URL encoding the string ... we've just been replacing
whitespace with underscores and stripping out things like "< > : ? * / \
|" - all your basic characters that Windows will complain about in a
filename.

- Clayton
_______________________________________________
Active4D-dev mailing list
Active4D-dev@...
http://mailman.aparajitaworld.com/mailman/listinfo/active4d-dev
Archives: http://mailman.aparajitaworld.com/archive/active4d-dev/