It'd be wonderful if the remote URL source would accept URLs which, while not looking like a file source, do provide a filename in the Content-Type or Content-Disposition header.

For example, if I download http://ga.berkeley.edu/filedepot_download/275/209, my browser automatically determines that the proper file name is Delegates_101104_agenda_0.pdf because the server returns the headers

Content-Disposition: attachment; filename="Delegates_101104_agenda_0.pdf"
Content-Type: application/pdf; name="Delegates_101104_agenda_0.pdf"

The $filename variable could easily be overridden by the name attribute of Content-Type, which could be extracted from $info['content_type'] in remote.inc.

Comments

bfroehle’s picture

Status: Active » Needs review
StatusFileSize
new1.17 KB

Since Cotent-Type is much easier to extract from cURL than Content-Disposition, attached is a patch which trusts the server provided filename as long as Content-Type has the form ...name="{filename}"....

quicksketch’s picture

Thanks! What a great idea. I'd be happy to include this feature. I think it could use a few lines of comments on what's going on here, but otherwise looks great. We don't normally use named placeholders in regexs, so for consistency it'd probably be good to replace ?P<filename>.+? with just .+? and refer to it later as $matches[1].

bfroehle’s picture

@quicksketch: Here's an updated patch that removes the named placeholder in the regex and adds some comments.

quicksketch’s picture

Perfect! I'll give this a test and if it works as advertised I'll include it and make sure it's in the next release.

bfroehle’s picture

Even better! I whipped up a new patch which uses the Content-Disposition field to read the filename. Note that I've chosen to do this in lieu of checking the Content-Type field, as I've generally found the name in Content-Type to be redundant.

Also the regular expression should be more robust to allow for filename specification of the form filename="FILENAME WITH SPACES.EXT" or filename=FILENAME.EXT.

quicksketch’s picture

Component: Code » General

I know it's been ages (we haven't had any releases in a long, long time). I'll still review this and include in the 1.3 release.

quicksketch’s picture

Status: Needs review » Fixed
StatusFileSize
new2.74 KB
new2.69 KB

I've committed the attached patches to the project. It's the same approach @bfroehle provided only I swapped the use of a global variable for a get/set function with a static variable.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

nonsimilar’s picture

Issue summary: View changes
Status: Closed (fixed) » Active

Sorry to reopen an old issue without posting a patch, but it's really a minor fix:

the two preg_match() in _filefield_source_remote_parse_header() should really be case-insensitive as sometimes the server returns "content-disposition" and not "Content-Disposition" (e.g. Dropbox).

  • quicksketch committed 8fe5be3 on 8.x-1.x
    Issue #967992 by bfroehle and quickksetch: Get filename from Content-...

  • quicksketch committed 499d613 on 7.x-1.x
    Issue #967992: Making header checks case-insensitive.
    
quicksketch’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Status: Active » Fixed

Thanks @nonsimilar. I've made the preg_match use the insensitive flag.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.