Home > Mobile >  download attribute corrupt file name when using query string
download attribute corrupt file name when using query string

Time:03-04

I have a file called in the following way: /storage/1_aviary-image-1429352137570.jpeg?1646327099. Within the blade view I have created a download link:

<a href="{{ $item['url'] }}" 
                             download="{{ $item['url'] }}" target="_blank">
   <span ></span>
</a>

When I download the file, for some reason I get: _storage_1_aviary-image-1429352137570.jpeg_1646327099

As you can see the ? was replaced by _.

I have never encountered this problem, could someone help me to understand what's going on?

Kind regards

CodePudding user response:

The problem is that the attribute value for download is optional, and when set will set what downloaded file will be named as. If you don't set it, then the filename will be what you for it in the href value.

That is, the following is valid, without setting download's value:

<a href="somefile.txt" download>

Since a ? is not a valid filename char, it is being gracefully replaced by the underscore.

The solution then is to not include the ? for the download's value, but keep it in your href value.

SOLUTION:

<a href="{{ $item['url'] }}" 
                             download="{{ $item['filename'] }}" target="_blank">
   <span ></span>
</a>

Where $item['filename'] would be the name of the file to download without the ? and timestamp.

  • Related