|
112 | 112 | temp_url_sig=da39a3ee5e6b4b0d3255bfef95601890afd80709&
|
113 | 113 | temp_url_expires=1323479485&inline
|
114 | 114 |
|
| 115 | +In some cases, the client might not able to present the content of the object, |
| 116 | +but you still want the content able to save to local with the specific |
| 117 | +filename. So you can cause ``Content-Disposition: inline; filename=...`` to be |
| 118 | +set on the response by adding the ``inline&filename=...`` parameter to the |
| 119 | +query string, like so:: |
| 120 | +
|
| 121 | + https://swift-cluster.example.com/v1/AUTH_account/container/object? |
| 122 | + temp_url_sig=da39a3ee5e6b4b0d3255bfef95601890afd80709& |
| 123 | + temp_url_expires=1323479485&inline&filename=My+Test+File.pdf |
| 124 | +
|
115 | 125 | ---------------------
|
116 | 126 | Cluster Configuration
|
117 | 127 | ---------------------
|
@@ -220,9 +230,15 @@ def get_tempurl_keys_from_metadata(meta):
|
220 | 230 | if key.lower() in ('temp-url-key', 'temp-url-key-2')]
|
221 | 231 |
|
222 | 232 |
|
223 |
| -def disposition_format(filename): |
224 |
| - return '''attachment; filename="%s"; filename*=UTF-8''%s''' % ( |
225 |
| - quote(filename, safe=' /'), quote(filename)) |
| 233 | +def disposition_format(disposition_type, filename): |
| 234 | + # Content-Disposition in HTTP is defined in |
| 235 | + # https://tools.ietf.org/html/rfc6266 and references |
| 236 | + # https://tools.ietf.org/html/rfc5987#section-3.2 |
| 237 | + # to explain the filename*= encoding format. The summary |
| 238 | + # is that it's the charset, then an optional (and empty) language |
| 239 | + # then the filename. Looks funny, but it's right. |
| 240 | + return '''%s; filename="%s"; filename*=UTF-8''%s''' % ( |
| 241 | + disposition_type, quote(filename, safe=' /'), quote(filename)) |
226 | 242 |
|
227 | 243 |
|
228 | 244 | def authorize_same_account(account_to_match):
|
@@ -413,14 +429,20 @@ def _start_response(status, headers, exc_info=None):
|
413 | 429 | else:
|
414 | 430 | existing_disposition = v
|
415 | 431 | if inline_disposition:
|
416 |
| - disposition_value = 'inline' |
| 432 | + if filename: |
| 433 | + disposition_value = disposition_format('inline', |
| 434 | + filename) |
| 435 | + else: |
| 436 | + disposition_value = 'inline' |
417 | 437 | elif filename:
|
418 |
| - disposition_value = disposition_format(filename) |
| 438 | + disposition_value = disposition_format('attachment', |
| 439 | + filename) |
419 | 440 | elif existing_disposition:
|
420 | 441 | disposition_value = existing_disposition
|
421 | 442 | else:
|
422 | 443 | name = basename(env['PATH_INFO'].rstrip('/'))
|
423 |
| - disposition_value = disposition_format(name) |
| 444 | + disposition_value = disposition_format('attachment', |
| 445 | + name) |
424 | 446 | # this is probably just paranoia, I couldn't actually get a
|
425 | 447 | # newline into existing_disposition
|
426 | 448 | value = disposition_value.replace('\n', '%0A')
|
|
0 commit comments