Vichuploaderbundle: absolute path on File rather than Relative

Created on 16 Oct 2019  路  8Comments  路  Source: dustin10/VichUploaderBundle

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
Under Discussion

Most helpful comment

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

All 8 comments

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

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

See discussion in #493

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?

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

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

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

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?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

archie18 picture archie18  路  6Comments

manguecreative picture manguecreative  路  4Comments

ngilain picture ngilain  路  5Comments

eved42 picture eved42  路  7Comments

vialcollet picture vialcollet  路  5Comments