Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow simple file download #3

Open
FGasper opened this issue Dec 4, 2015 · 9 comments
Open

Allow simple file download #3

FGasper opened this issue Dec 4, 2015 · 9 comments

Comments

@FGasper
Copy link

FGasper commented Dec 4, 2015

Right now if I want the GABC of a chant, my browser makes me save it to disk. I then have to hunt down that file, open it up, then manipulate it.

How hard would it be to allow a “simple” download of the file — ideally even an “open as text” so I can just cut/paste the text into an editor?

@olivierberten
Copy link
Collaborator

Well... I guess this all depends on your browser configuration... The server sends it as plain text...

On my computer, clicking on it with Firefox lets me open it with my usual text editor...

@bbloomf
Copy link

bbloomf commented Mar 29, 2016

I think @FGasper is referring to the fact that it sends it as plain text, but with the header Content-Disposition:attachment; which causes the browser to download it and save to disk rather than simply displaying it in the browser.

@igneus
Copy link
Contributor

igneus commented Oct 30, 2016

@FGasper

How hard would it be to allow a “simple” download of the file — ideally even an “open as text” so I can just cut/paste the text into an editor?

As @bbloomf correctly observes, it's mainly a matter of not sending a HTTP header Content-Disposition: attachment, which is currently being sent at

header('Content-Disposition: attachment; filename='.$filename.$suffix.'.'.'gabc');
Removing the line would lead to the behaviour you wish - the browser would display the gabc as plaintext.

It would, however, also have another, less desired effect: if you wanted to save the gabc, the save dialog would probably offer you download.php as file name and you would have to manually enter some sane filename, whereas now the filename is being generated for you.

It would be possible to add - aside of the "Download GABC" - another link "View GABC". It would be handled the same way, except of sending the abovementioned HTTP header. (@olivierberten if you want me to, I will be happy to volunteer to make this change.)

Another way, with significantly greater amount of work, would be changing the URL schema, so that gabc download would have a "pretty" URL with a sane filename, e.g. /scores/all--abducentur--vatican.gabc . The header would not be sent, thus the gabc would by default be displayed as plaintext by browsers, but it would be possible to save it quickly with a pretty filename (this time taken from the URL, not from a HTTP header).

@FGasper
Copy link
Author

FGasper commented Oct 30, 2016

@igneus Just set the type to “inline” rather than “attachment”, then specify the filename?

@FGasper
Copy link
Author

FGasper commented Oct 30, 2016

@FGasper
Copy link
Author

FGasper commented Oct 30, 2016

(I didn’t try this, but as per the spec it might work.)

@FGasper
Copy link
Author

FGasper commented Oct 30, 2016

It works. Download/save the content from this server:

#!/usr/bin/env perl

use strict;
use warnings;
use autodie;

use IO::Socket::INET ();

my $srv = IO::Socket::INET->new(
    LocalPort => 1234,
    Listen => 1,
    Reuse => 1,
);

$srv or die "[$!] [$@]\n";

while ( my $cn = $srv->accept() ) {
    fork or do {
        print {$cn} "HTTP/1.0 200 OK\r\n";
        print {$cn} qq<Content-Disposition: inline; filename="the_file.txt"\r\n>;
        print {$cn} "Content-Type: text/plain; charset=utf-8\r\n\r\n";
        print {$cn} "Some content …\r\n";
        close $cn;
        exit;
    };
}

@igneus
Copy link
Contributor

igneus commented Oct 30, 2016

@FGasper I only read https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition and came this way to the wrong assumption that
Content-disposition: inline; filename="filename.txt"
is not a valid combination. Now I see I was wrong.

@FGasper
Copy link
Author

FGasper commented Oct 30, 2016

Alternatively, maybe add a <textfield readonly> to the page and showing the GABC there, cut/paste-able.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants