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.
- Some APIs provide resource URLs that do not point directly to a file, but instead redirect the user to the file. For example,
https://www.instagram.com/p/B9vy5EdgZX1/media/?size=l
is proviuded by the Instagram API, but this actually redirects tohttps://scontent-lht6-1.cdninstagram.com/v/t51.2885-15/fr/e15/p1080x1080/89738651_155780038891572_5224457300248488192_n.jpg?_nc_ht=scontent-lht6-1.cdninstagram.com&_nc_cat=100&_nc_ohc=rGVubVRCFoAAX8YKjNO&oh=76c6ac182e0432bfffce7539e372631d&oe=5EB77DAB
- This redirect causes issues for
\Drupal\feeds\Feeds\Target\File::getFileName
which expects to get a URI that contains a file extension that it can pass to\Drupal\Core\File\FileSystem::basename
- One fix would be to make a request to
$url
as part of\Drupal\feeds\Feeds\Target\File::getFileName
and update the value of$url
whenever a redirect takes place.
Patch incoming :)
Comments
Comment #2
Phil Wolstenholme CreditAttribution: Phil Wolstenholme as a volunteer commentedComment #3
Phil Wolstenholme CreditAttribution: Phil Wolstenholme as a volunteer commentedHere's a rough patch that uses Guzzle to work out the 'final' URL of a resource after any redirects.
It also includes the changes proposed in https://www.drupal.org/project/feeds/issues/2977565#comment-13262487 to prevent the failures caused by query strings in a URL (another common thing with image resources returned by APIs).
Comment #4
Phil Wolstenholme CreditAttribution: Phil Wolstenholme as a volunteer commentedComment #5
Phil Wolstenholme CreditAttribution: Phil Wolstenholme as a volunteer commentedHere's an updated patch that adds the missing use statement for
use GuzzleHttp\TransferStats;
Comment #8
Phil Wolstenholme CreditAttribution: Phil Wolstenholme as a volunteer commentedI'm not sure wny the test is failing, the patch seemed to work okay for me locally with a range of URLs. Hopefully the patch can help someone else figure out a version that also passes the tests!
Comment #9
Phil Wolstenholme CreditAttribution: Phil Wolstenholme as a volunteer commentedAh, I guess we need to check if we're dealing with a local file path/URI or a remote URL, and only use Guzzle to follow redirects if it's a remote URL.
Comment #10
damondt CreditAttribution: damondt commentedI took a slightly different approach putting the redirect calculation in getFile(). I also made it a selectable option in the target config form because of the performance impact it has.
Comment #11
damondt CreditAttribution: damondt commentedCleaned up the patch.
Comment #12
lesleyfernandes CreditAttribution: lesleyfernandes commentedUpdating the patch to work with the latest feeds module updates.
Comment #13
lesleyfernandes CreditAttribution: lesleyfernandes commented