Solved

Force the download of PDF from third party URL using mod_rewrite or similar

Posted on 2010-08-24
8
439 Views
Last Modified: 2012-05-10
We have a CDN provider that provides PDF files though for some reason they do not progressively download as they would if being download by a Apache web server. There is not a way from the CDN side of providing a method to force downloading of files rather then opening by default. I can handle this in Apache if the file were hosted locally by using:
AddType application/octet-stream .pdf

Open in new window

or
<FilesMatch "\.(?i:pdf)$">
  ForceType application/octet-stream
  Header set Content-Disposition attachment
</FilesMatch>

Open in new window

but we are not hosting the file but instead providing a redirect to the CDN. Is there a way to force a redirected link to download rather than open? Below is our current rewrite rule which in short takes any requested file in the dl directory and requests it from the CDN. Can we control the remote behavior?

RewriteRule ^/dl/(.*)$ http://c0002.cdn1.cloudfiles.rackspacecloud.com/$1 [R=302,L]

Open in new window

0
Comment
Question by:adamshields
  • 4
  • 4
8 Comments
 
LVL 9

Expert Comment

by:fcontrepois
ID: 33520218
You should use mod_proxy to change the headers
0
 
LVL 3

Author Comment

by:adamshields
ID: 33520307
Can you elaborate or provide an example?
0
 
LVL 9

Expert Comment

by:fcontrepois
ID: 33520515
Hi,

let the browsers download the pdf from you and you creating a redirection to the remote host and supply the right header.

The idea is to use the following directives, probably with some tweak


ProxyPass /dl/ http://c0002.cdn1.cloudfiles.rackspacecloud.com/
+
AddType application/octet-stream .pdf





0
Flexible connectivity for any environment

The KE6900 series can extend and deploy computers with high definition displays across multiple stations in a variety of applications that suit any environment. Expand computer use to stations across multiple rooms with dynamic access.

 
LVL 3

Author Comment

by:adamshields
ID: 33520656
Would this effect the CDN caching or speed since it has to proxy through my host?
0
 
LVL 9

Accepted Solution

by:
fcontrepois earned 500 total points
ID: 33520772
All requests - particularly download - would go through your host, so if you use the cloud for bandwidth then this is not a good solution. If you choose cloud for space then yes.

The "problem" is by redirecting (301)  the browser to rackspace you loose control on the requests for pdf.
0
 
LVL 3

Author Comment

by:adamshields
ID: 33520825
That's what I was thinking. We are using it for bandwidth in this scenario. Guess we'll stick with ZIP files as the CDN properly prompts for download. Unless you can think of any  other workarounds?
0
 
LVL 9

Assisted Solution

by:fcontrepois
fcontrepois earned 500 total points
ID: 33523171
After receiving a 301 the browser will just create a new request to the 301 destination so you don't have any possibilities to change anything, it's between them.
0
 
LVL 3

Author Closing Comment

by:adamshields
ID: 33524165
Thanks for the insight.
0

Featured Post

Don't miss ATEN at NAB Show April 24-27!

Visit ATEN at NAB Show to learn how our "Seamlessly Entertaining" solutions deliver fast, precise video streaming without delays for the broadcasting and media environment. ATEN will showcase its 16x16 Modular Matrix Switch (VM1600) and KVM Over IP Solution (KE6900 series).

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question