2

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
  • 575
  • 8
  • 22
  • Unfortunately, your link to `forum.owncloud.org` is dead, or at least it redirects to what looks like the front page of a totally new forum. The URL is not in the Wayback Machine and I couldn't find any relevant discussion on the new forum. 6 years later, I wonder if ownCloud has implemented a way to serve 'raw files' based on their path inside the user's ownCloud account? – sjy Sep 23 '20 at 03:28
  • [This forum thread from 2016](https://central.owncloud.org/t/view-and-not-download-public-shared-files/2869/3) seems to confirm that the only option is to reverse proxy or patch ownCloud to return a different `Content-Disposition` (or `X-Download-Options`?) header. – sjy Sep 23 '20 at 03:32

1 Answers1

2

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
    }
}
Giacomo1968
  • 53,069
  • 19
  • 162
  • 212
ceremcem
  • 575
  • 8
  • 22