bithost-gmbh / pdfviewhelpers

TYPO3 CMS extension that provides various Fluid ViewHelpers to generate PDF documents.
GNU General Public License v3.0
44 stars 20 forks source link

<pdf:image ViewHelper cannot handle spaces in image filenames #180

Closed int-sst closed 3 years ago

int-sst commented 3 years ago

Hi,

when calling the <pdf:image> ViewHelper with an image containing urlencoded spaces, e.g.

<pdf:image src="fileadmin/user_upload/_b2b/products/11009379_tv%20MOLISE AH_BBS.jpg"></pdf:image>

we are receiving an error message

(1/2) #1536560752 Bithost\Pdfviewhelpers\Exception\ValidationException
Invalid file src provided, must be either a uid, combined identifier, path/filename or implement FileInterface. Folder "/user_upload/_b2b/products/11009379_tv%20MOLISE AH_BBS.jpg/" does not exist. ERROR: 1536560752

TYPO3 version(s): 10.4.12 pdfviewhelpers version: 2.3.4

A solution is to urldecode the src in EXT:pdfviewhelpers/Classes/ViewHelpers/ImageViewHelper.php

$imageFile = $this->conversionService->convertFileSrcToFileObject(urldecode($this->arguments['src']));

Regards, Saša

maechler commented 3 years ago

Hi Saša,

Thanks for this will written issue. I would however argue that fileadmin/user_upload/_b2b/products/11009379_tv%20MOLISE AH_BBS.jpg is a path and as such %20 should be interpreted as %20 literally instead of like a space.

It would probably be different if it was a file URI, such as: file:///some/absolute/path/to/fileadmin/user_upload/_b2b/products/11009379_tv%20MOLISE AH_BBS.jpg But even with file URIs the PHP functions do not seem to decode %20 to a space.

I would recommend you to use an URL decode ViewHelper in front of the path:

<pdf:image src="{filePath -> v:format.url.decode()}"></pdf:image>

Or even better find out where this %20 comes from and avoid it.

@macjohnny What do you think?

int-sst commented 3 years ago

Hi, the encoded filename comes from

<pdf:image src="{f:uri.image(image:'{someImageObj}')}" />

It has been uploaded via Filelist.

maechler commented 3 years ago

If you already have an image object, you can just pass it as the source:

<pdf:image src="{someImageObj}" />

Does that work for you?

int-sst commented 3 years ago

The same error occurs when using <pdf:image src="{someImageObj}" />

Invalid file src provided, must be either a uid, combined identifier, path/filename or implement FileInterface. ERROR: 1536560752
maechler commented 3 years ago

Then {someImageObj} is probably not an image object implementing FileInterface. Could you please show us the output of <f:debug>{someImageObj}</f:debug>?

maechler commented 3 years ago

Closing because of no response within 3 weeks. If you would like to continue the discussion, please feel free to comment.