Laravel-medialibrary: addMediaFromUrl fail when url is little bit weird

Created on 21 Mar 2018  路  4Comments  路  Source: spatie/laravel-medialibrary

Version: 6.9.0

When I call addMediaFromUrl with little weird url(but valid), it fails and it's conversion job was remaining on the queue and continuosly consuming disk space with temp files.

Below is exception message.

n Decoder.php line 26:

  Unable to read image from path (/private/var/folders/vc/slpzd9qj1c34kb5vx7j97_ym0000gn/T/GlideXMMkV9).  


In Decoder.php line 22:

  no decode delegate for this image format `' @ error/constitute.c/ReadImage/509  

Here's one of url causes above problem.

https://dthumb-phinf.pstatic.net/?src=%22https%3A%2F%2Fshop-phinf.pstatic.net%2F20180116_81%2Flovelyamie_1516031621836Wd9JR_JPEG%2F39338801478811043_156275708.jpg%3Ftype%3Dm450%22&type=ff120

And this is what I study about this problem til now.

addMediaFromUrl function guesses file name from url with below code.

$filename = basename(parse_url($url, PHP_URL_PATH));

so I tested it with below code

basename(parse_url('https://dthumb-phinf.pstatic.net/?src=%22https%3A%2F%2Fshop-phinf.pstatic.net%2F20180116_81%2Flovelyamie_1516031621836Wd9JR_JPEG%2F39338801478811043_156275708.jpg%3Ftype%3Dm450%22&type=ff120', PHP_URL_PATH));

and returns empty string.

I think in this case it would be great if medialibrary create a temporary name with extension generated from mime-type.

Thanks for great work.

bug enhancement good first issue

Most helpful comment

Fixed

All 4 comments

I'd accept a PR (with tests) that adds this to the package.

Fixed

Wow thanks for quick response.
By the way, sample url I provided is not permanent. Test case will fail after the file removed.

Yeah, I'll take care of changing that test soon.

Was this page helpful?
0 / 5 - 0 ratings