Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom fileName/filePath prior toCollectionOnDisk #43

Closed
spawn-guy opened this issue Aug 10, 2015 · 1 comment
Closed

Custom fileName/filePath prior toCollectionOnDisk #43

spawn-guy opened this issue Aug 10, 2015 · 1 comment

Comments

@spawn-guy
Copy link

I've seen it mentioned a few times, but here i am.
I am aware of feature to "rename" $media->file_name, but this is for After the saving on Disk and all the manipulations.

This doesn't work with \Spatie\MediaLibrary\FileAdder\FileAdder objects, that you "actually" get after $model->addMedia($request->file('contents'))

Also, as some ppl noticed: the copyToMediaLibrary does have an optional $subDirectory parameter. However, I haven't found a way(in the docs) to set this parameter anywhere.

Questions are:

  • how to set targetFilename Prior the saveOnDisc?
  • how to set $subDirectory (but this could break compatibility.. as file_name should also be updated)?
  • if media->file_name will have sub-directories(slashes in file_name) will it break anything?
@freekmurze
Copy link
Member

Hi, thanks for your input.

In the newly released v3.1.0 of the package there is a new method usingFileName() to choose the filename with which it gets added to the medialibrary.

$newsItem->addMedia('test.txt')->usingFileName('othertext.txt')->toMediaLibrary();

The above method only changes the name of the underlying file. If you want to change the name of the media object as well you can do this:

$newsItem
   ->addMedia('test.txt')
   ->usingName('some other name')
   ->usingFileName('othertext.txt')
   ->toMediaLibrary();

There is currently no support for using subdirectories. The copyToMediaLibrary-function is used internally by the package. There is an extra parameter there so the package can handle storing conversions.

I haven't tested using slashes in the filename, it might work for now, but I don't recommend it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants