GregoBase icon indicating copy to clipboard operation
GregoBase copied to clipboard

Allow simple file download

Open FGasper opened this issue 10 years ago • 9 comments

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?

FGasper avatar Dec 04 '15 07:12 FGasper

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...

olivierberten avatar Dec 10 '15 11:12 olivierberten

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.

bbloomf avatar Mar 29 '16 16:03 bbloomf

@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 https://github.com/gregorio-project/GregoBase/blob/a10e3d2f3ed6d3b282f33f56cf78375ef83980e0/download.php#L64 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).

igneus avatar Oct 30 '16 14:10 igneus

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

FGasper avatar Oct 30 '16 14:10 FGasper

https://tools.ietf.org/html/rfc6266#section-4.1

FGasper avatar Oct 30 '16 14:10 FGasper

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

FGasper avatar Oct 30 '16 14:10 FGasper

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;
    };
}

FGasper avatar Oct 30 '16 14:10 FGasper

@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.

igneus avatar Oct 30 '16 14:10 igneus

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

FGasper avatar Oct 30 '16 15:10 FGasper