Laravel-medialibrary: addMediaFromUrl not working redirect url

Created on 8 Apr 2020  路  1Comment  路  Source: spatie/laravel-medialibrary

Most helpful comment

Hi,

The addMediaFromUrl function needs to use HTTP context options. Three quick ways for adding this feature:

  1. by adding a new config option. We can override and revert the config at runtime (for example for cases when some urls require autentication). It`s not nice, but avoids the breaking change in option 2.

  2. by adding a new $httpContext param in the addMediaFromUrl function (it will be a breaking change though)

public function addMediaFromUrl(string $url, array $httpContext = null, ...$allowedMimeTypes): FileAdder
    {
        if (! $stream = @fopen($url, 'r', false, $httpContext)) {
            throw UnreachableUrl::create($url);
        }
        ...
  1. a combination of the first two options which allows overriding default config values by merging the config array with the $httpContext param array.

@tnduc Until this feature is available, you can simply override the InteractsWithMedia trait addMediaFromUrl function and use the approach in options 2 above.

>All comments

Hi,

The addMediaFromUrl function needs to use HTTP context options. Three quick ways for adding this feature:

  1. by adding a new config option. We can override and revert the config at runtime (for example for cases when some urls require autentication). It`s not nice, but avoids the breaking change in option 2.

  2. by adding a new $httpContext param in the addMediaFromUrl function (it will be a breaking change though)

public function addMediaFromUrl(string $url, array $httpContext = null, ...$allowedMimeTypes): FileAdder
    {
        if (! $stream = @fopen($url, 'r', false, $httpContext)) {
            throw UnreachableUrl::create($url);
        }
        ...
  1. a combination of the first two options which allows overriding default config values by merging the config array with the $httpContext param array.

@tnduc Until this feature is available, you can simply override the InteractsWithMedia trait addMediaFromUrl function and use the approach in options 2 above.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jam1e picture jam1e  路  3Comments

brendt picture brendt  路  4Comments

stayallive picture stayallive  路  4Comments

swash13 picture swash13  路  3Comments

eichgi picture eichgi  路  3Comments