How to show file in browser instead of downloading?

1

I'm using Owncloud (behind Nginx) to share a file. When I generate a share link, the link points me to the download page or if I append "&download", it immediately starts downloading the file.

My need is, as Github's "Raw file" option, serve a text file in the browser so I may use that file as an input to an another service (like draw.io)

This should be an owncloud property as this person asks for, but I thought I may work around of this problem with Nginx.

May I change some headers or something in order to make a browser show the file's contents instead of downloading by appending /my-raw-command to the url?

For example, if the original download url is this: www.example.com/myfile.txt&download, I want it to be shown in the browser if I type www.example.com/myfile.txt&download/my-raw-command

Would somebody give me any tips to start from?

ceremcem

Posted 2014-11-12T12:24:32.347

Reputation: 363

Answers

0

I understand that I needed to remove Content-Disposition: ... line from the response headers. Since it was easier, I have solved the problem by editing/hacking OwnCloud’s PHP code.

In the lib/private/response.php file I changed setContentDispositionHeader function as follows:

static public function setContentDispositionHeader( $filename, $type = 'attachment' ) {
    if (OC_Request::isUserAgent(array(
            OC_Request::USER_AGENT_IE,
            OC_Request::USER_AGENT_ANDROID_MOBILE_CHROME,
            OC_Request::USER_AGENT_FREEBOX
        ))) {
        header( 'Content-Disposition: ' . rawurlencode($type) . '; filename="' . rawurlencode( $filename ) . '"' );
    } else {
                    // cca-hack-id:make-raw-output-property ###
                    // cca-hack-id:make-raw-output-property ### I needed something like "raw" format of github.com. 
                    // cca-hack-id:make-raw-output-property ###
                    // cca-hack-id:make-raw-output-property ### Usage with an example: 
                    // cca-hack-id:make-raw-output-property ###   1. share a single file and get a public link (MY_PUBLIC_LINK) for the file. 
                    // cca-hack-id:make-raw-output-property ###   2. get the file's direct url (MY_PUBLIC_LINK&download)
                    // cca-hack-id:make-raw-output-property ###   3. append '&raw' to the url: MY_PUBLIC_LINK&download&raw
                    // cca-hack-id:make-raw-output-property ###
                    // cca-hack-id:make-raw-output-property ### If you want to undo this hack, remove all lines which contains 'cca-hack-id:make-raw-output-property' string. 
                    // cca-hack-id:make-raw-output-property ###

                    if (!array_key_exists('raw', $_GET)) {  // cca-hack-id:make-raw-output-property
                header( 'Content-Disposition: ' . rawurlencode($type) . '; filename*=UTF-8\'\'' . rawurlencode( $filename )
                                             . '; filename="' . rawurlencode( $filename ) . '"' );
        } // cca-hack-id:make-raw-output-property
    }
}

ceremcem

Posted 2014-11-12T12:24:32.347

Reputation: 363