Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I am importing a feed with dynamic enclosures like:
http://productimages.wehkamp.nl/is/image/Wehkamp/?src=Wehkamp%2F415538_pb_01
This type of URL leads to errors during getFile($destination) in FeedsParser.inc:
File temporary://filA163.tmp could not be copied, because the destination directory is not configured correctly.
The reason is that my URL has no basename($filename)
Actually, once you fetch that image, the actual filename dynamically becomes productimages.wehkamp.nl.jpg
in the example above. But basename() does not derive that from the URL. It doesn't do the remote call to see what is the actual returned filename.
Comment | File | Size | Author |
---|---|---|---|
#17 | news-cred-image-import-1104378-17.patch | 11.28 KB | AlexKirstenZA |
#16 | feeds-get_filename_from_http_headers-1104378-10.patch | 6.19 KB | fougere |
#12 | feeds-get_filename_from_http_headers-1104378-8.patch | 2.81 KB | kenorb |
| |||
#11 | feeds-get_filename_from_http_headers-1104378-7.patch | 2.8 KB | kenorb |
| |||
#8 | feeds-get_filename_from_http_headers-1104378-6.patch | 2.14 KB | kenorb |
|
Comments
Comment #1
marcvangendSubscribe.
I have worked around this problem before by placing a custom php script (imagewrapper.php) on my server that accepts a clean url (just like Drupal's index.php does), retrieves the image with CURL and returns it. This way you end up with filenames exactly like you want them, but the downside is the extra request in the chain.
This is what my imagewrapper.php looks like:
Note that I do not really recommend this approach, it's only a workaround.
Comment #2
riho CreditAttribution: riho commentedI had the same problem, so I created a patch for it. It uses the file name it finds from the header or falls back to the basename.
Comment #3
stewart.adam CreditAttribution: stewart.adam commentedRebased to latest git (7.x-2.x I reworked riho's patch a little bit as http_request_get() returns its header array using lowercase keys, so checking against
...->headers['Content-Dispotion']
would fail.I've also added a secondary regex to support the case where the server doesn't properly quote the filename, such as some IIS servers. branch).
Comment #5
stewart.adam CreditAttribution: stewart.adam commentedAttached patch checks for the presence of the Content-Disposition header to prevent PHP notices... This one should pass the test bot.
Comment #6
thatpixguy CreditAttribution: thatpixguy commentedI need this feature and just made a patch of my own, but before posting it I found this issue request :)
The latest submitted patch seems more complete than my solution, so I won't add noise with mine.
pix
Comment #7
twistor CreditAttribution: twistor commentedhmm yes.
Comment #8
kenorb CreditAttribution: kenorb commentedConverted against the latest dev.
Comment #9
MegaChriz CreditAttribution: MegaChriz as a volunteer commented#2510788: Remove query string from path in FeedsEnclosure. looks related, adding for reference.
Comment #10
kenorb CreditAttribution: kenorb commentedExpanded patch and attached below.
Comment #11
kenorb CreditAttribution: kenorb commentedCombined #8 patch with #2611014-4: Feeds doesn't import remote images which have no proper extension (such as ASP) as they're fairly related.
Comment #12
kenorb CreditAttribution: kenorb commentedAs #11, but with small fix:
As $this->allowedExtensions isn't an array, but string.
Tested Feed import and it works fine.
Comment #13
c.dan CreditAttribution: c.dan commentedDownloaded latest dev version + applied patch #12. Doesn't save the file.
My links are in this format:
http://picscdn.redblue.de/doi/pixelboxx-mss-62050889/fee_786_587_png/101-Dalmatinerna-Barn-DVD
Comment #14
fougere CreditAttribution: fougere commentedSmall modification to the previous patch.
The allowed extension check was done before retrieving the filename in the http headers.
So it fails unless your url already ends with the correct extension (like in comment #13).
Comment #16
fougere CreditAttribution: fougere commentedUnit test fix. The watchdog message for invalid extensions was not the same as before.
Comment #17
AlexKirstenZA CreditAttribution: AlexKirstenZA commentedAdjusted the patch submitted in comment #16, in order to allow NewsCred images to be imported into image fields.
Comment #18
MegaChriz CreditAttribution: MegaChriz as a volunteer commentedThe last patch seems to undo a lot of other changes made in other issues.