VichUploaderBundle icon indicating copy to clipboard operation
VichUploaderBundle copied to clipboard

absolute path on File rather than Relative

Open webmasterMeyers opened this issue 5 years ago • 8 comments

BC Break Report

Q A
BC Break yes
Version 1.10.2

Summary

Considering this entity mapping

    /**
     * @Assert\NotBlank()
     * @Vich\UploadableField(mapping="assets", fileNameProperty="filename")
     */
    private $file;

Previous behavior

in version 1.10.1 $profilePhoto->getFile()->getPathname() will return a relative path like photos/123456.jpg

Current behavior

in version 1.10.2 $profilePhoto->getFile()->getPathname() will return an absolute path like /var/www/html/example.com/public_html/photos/123456.jpg

How to reproduce

  1. dump the contents of a "file", note the path variables
  2. update vich uploader bundle
  3. dump the contents of a "file", note the path variables

webmasterMeyers avatar Oct 16 '19 15:10 webmasterMeyers

I am using Flysytem with both a local and S3 adaptor depending on the dev or prod environment.

I suspect maybe the change in Storage/FlysystemStorage.php is the culprit

webmasterMeyers avatar Oct 16 '19 15:10 webmasterMeyers

yes, reverting that single change returns the previous behaviour. Why the change? How else would I go about getting the relative file path?

webmasterMeyers avatar Oct 16 '19 16:10 webmasterMeyers

See discussion in #493

garak avatar Oct 16 '19 16:10 garak

fair enough, so the expected behaviour is to receive an absolute path then. What is the best way to get the relative path? or do I just hard code it?

webmasterMeyers avatar Oct 16 '19 17:10 webmasterMeyers

You should know the path of your assets, since you configured it. Just retrieve such path from configuration

garak avatar Oct 17 '19 07:10 garak

Hi everyone ! Another problem is that the method applyPathPrefix() is not registred on the interface AdapterInterface.php.

So, when you use the MemoryAdapter from Flysystem, you got an error :

Call to undefined method League\Flysystem\Memory\MemoryAdapter::applyPathPrefix() 

#1 /builds/xxxx/vendor/vich/uploader-bundle/Storage/FlysystemStorage.php:64

guillaume-ro-fr avatar Oct 17 '19 14:10 guillaume-ro-fr

I summon @leigh-ols (being the auhor of PR that closed related issue)

garak avatar Oct 17 '19 14:10 garak

Ah,... that's a difficult one.

I have to be honest i'm not particularly familiar with either of the two code bases, so I'm far from an authority.

What we had before didn't work at all, so although PR #1007 is apparently not perfect, it's still an improvement on what we had.

Does anyone have any ideas on how to get the absolute path in a manner that sticks religiously to the interfaces of Flysystem?

leigh-ols avatar Oct 17 '19 15:10 leigh-ols