Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Filestream link open/save prompt

by ksublondie (Friar)
on Oct 31, 2013 at 15:03 UTC ( #1060589=perlquestion: print w/replies, xml ) Need Help??
ksublondie has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,

I have a web interface that uses, & sql2012 filestream to access multiple documents, mostly pdfs. When I initially set this up, I stored the docs on the server, but my last update uses sql to manage the new files (the existing files are still on the server). I'm using the following in the html template file:

<a href='[%IF form.Blob%]?rm=getDBFile&formid=[%form.FormId;ELSE; form +.FileName; END %]' target='_blank'> [% form.FormName %]</a>

And getDBFile is the following:

sub getDBFile{ my $self = shift; my $q = $self->query; my $formData=''; my $formid=$q->param('formid'); ... $self->header_props(-type => $type, -attachment => $fileName); return $formData; }

Everything works great, except if I'm getting the doc from the db using getDBFile, the browser prompts to open or save. If the link target is stored on the server, it doesn't prompt and just automatically opens the file in a new window.

No biggie, you say? Well, apparently not to my end users. Unfortunately, this is life & death to have an extra click. And it looks like the "remember this action" functionality was taken away in IE and doesn't work properly in FF without a plugin.

Is it possible to have them both not prompt?

Replies are listed 'Best First'.
Re: Filestream link open/save prompt
by keszler (Priest) on Oct 31, 2013 at 15:13 UTC
    Examine the HTTP headers returned from db vs file queries - what's different? Update getDBFile accordingly.


Re: Filestream link open/save prompt
by Corion (Pope) on Oct 31, 2013 at 15:37 UTC

    In addition to keszler's advice, also consider looking at the value of FormId resp. $fileName. The URL might end with .doc (or .docx) in one case, making IE treat the link as link to a Word file. If your FormId is something opaque, like a row id or an MD5, this might trigger different behaviour in IE (and other browsers).

    You might want to add (or remove) a Content-Disposition: attachment header if your ->header_props routine does not do that already. The Content-Disposition: attachment; filename=$fileName header would make the browser prompt the user. So I expect that you might want to remove it.

Re: Filestream link open/save prompt (template knows too much)
by Anonymous Monk on Nov 01, 2013 at 02:31 UTC

    I think your template knows too much about what the url should look like, the common way this is written is like

    <a href='[% form.fudgy_href %]' target='_blank'> [% form.FormName %] </a> or <a href='[% url_from_form( form ) %]' target='_blank'> [% form.FormName %] </a>

    That way the template doesn't change if the url changes, or if you switch from the  foo?rm=foo style to the  /foo/rm/foo style

    Also template modifiers don't get tempted to delete all the logic ... that belongs outside of the template :)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1060589]
Approved by ww
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2018-04-22 07:15 GMT
Find Nodes?
    Voting Booth?