Hi,
When you call \Illuminate\Filesystem\FilesystemAdapter::put() you have to set a pathargument which is supposed to be a full path, like foo/bar.png.
This is how flysystem's put and putStream methods work.
But, in case of the file passed to put() is a \Illuminate\Http\File or \Illuminate\Http\UploadedFile, the method \Illuminate\Filesystem\FilesystemAdapter::putFile is used, so the path passed will now be like : foo/bar.png/RandomString.guessedExtension.
See theses files to understand why:
It's really weird that this single method has a complete different behavior depending the type of the file you will pass to it.
A simple and dirty example (real one, very very simplified) to explain why it's a real problem :
// $file is an UploadedFile : Audio, or Image
$file = $this->resizeIfIsImage($file); // if file is an image, resize it, and return it as a blob.
$path = $this->getUploadPath(); // get the future full upload path (including name), depending of several arguments. examples : `foo/bar.png` or `foo/bar.mp3`
$this->storage->put($path, $file); // return a bool if image, or a new unwanted path if other.
In this example, for the same put method, the image will be stored as foo/bar.png but the audio file will be stored at foo/bar.mp3/8sSz4irZBvm9o1Hq.mpga !!
Quite weird and annoying...
I can make a PR if wanted (but don't want to make it for nothing..)
Thx
You can use putFile() and putFileAs() instead of put() to have more control over how laravel will store your file.
Yeah but the putFile* methods don't work like driver->put* ones !
So if I pass (like in my example) several type of file, the behavior will be completely different. Moreover, I can't pass a blob to putFile*, however I can pass any type of file in put.
I can manage my problem by converting on my side the UploadedFile to a stream before passing it to put, put this is exactly that you want to avoid:
// If the given contents is actually a file or uploaded file instance than we will
// automatically store the file using a stream. This provides a convenient path
// for the developer to store streams without managing them manually in code.
For me the real issue is to consider that the path provided to put is just a directory if $contents is a UploadedFile and a full path if not.
Same method, two behaviors !
$contents is a stream or blobput('foo.ext', $contents) will store it at the path foo.ext as planed.$contents is a UploadedFile or Fileput('foo.ext', $contents) will store it at the path foo.ext/RandomString.guessedExtension not as planed at all.I don't know if I success to make me understood.. :/
I understand but there's no plans to make such change at the moment
@themsaid Are you sure to close that?
As I said, for me It's a real bug, not just a proposal!
There are no plans to make such change at the moment, I suggest you open a new issue in the internals repository, it's where we keep such discussions and requests.
ok, I'll do that.
Thx for your answer!
I'm having the same problem. What did you do @mathieutu?..
Most helpful comment
@themsaid Are you sure to close that?
As I said, for me It's a real bug, not just a proposal!