This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Hello, I'm new to the world of October cms.
For a project, I have to change the public address and the storage path with the following. /storage/app/uploads/attachment_id/real_file_name.jpg. Something like the media folder but with 'sort_order' because I need this field. I do not know from where to get attachment_id so that I can use it in the storage path. It is in
protected $hidden = ['attachment_type', 'attachment_id', 'is_public'];
I suppose I have to use update method of plugin model to move the files to /storage/app/uploads/attachment_id .
How to do it ?
Last updated
Exword said: For a project, I have to change the public address and the storage path with the following. /storage/app/uploads/attachment_id/real_file_name.jpg.
Start by overriding \System\Models\File various getPath, getPartition and get__Directory functions as required: https://octobercms.com/docs/api/system/models/file
Define your model attach*** relationships with new descendant class \My\Plugin\Models\SortedFile
Yes and I had this idea to but when I writing something like
// Define the public address for the storage path.
public function getPublicPath()
{
$uploadsPath = Config::get('cms.storage.uploads.path', '/storage/app/uploads');
if ($this->isPublic()) {
$uploadsPath .= '/gallery/'. $this->attachment_id.'/';
}
else {
$uploadsPath .= '/protected';
}
return Url::asset($uploadsPath) . '/';
}
//Define the internal storage path.
public function getStorageDirectory()
{
$uploadsFolder = Config::get('cms.storage.uploads.folder');
if ($this->isPublic()) {
return $uploadsFolder . '/gallery/'. $this->attachment_id.'/';
}
else {
return $uploadsFolder . '/protected/';
}
}
It does not work. $this->attachment_id appears after I update the model. Is there a way to send it this attachment_id when the file is uploading?
Exword said: It does not work. $this->attachment_id appears after I update the model. Is there a way to send it this attachment_id when the file is uploading?
Yeah, attachment_id is probably filled too late because attachments use deferred bindings... see if comment at the end of events section is useful in your situation: https://octobercms.com/docs/database/model#events
Thank you for your help!
Maybe because I am newbie but I think there's something seriously wrong with fileuplud form widgets. Why from the fileuplud widget can not be selected storage location? Why when the file is deleted from the model, the file remains on the server and in the database? When the winter holidays come i will began to learn more about octobercms and hopefully make my own widget.
Last updated
1-6 of 6