plank / laravel-mediable Goto Github PK
View Code? Open in Web Editor NEWLaravel-Mediable is a package for easily uploading and attaching media files to models with Laravel
License: MIT License
Laravel-Mediable is a package for easily uploading and attaching media files to models with Laravel
License: MIT License
Getting the following error at the last step of installation when doing a php artisan migrate
using Laravel 5.4.15, MySql 5.6, PHP 7.1.2
[Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (SQL: alter table `media` add unique `media_disk_directory_filename_extension_unique`(`disk`, `directory`, `filename`, `extension`))
[PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes
I already have the following set up in my AppServiceProvider.php:
use Illuminate\Support\Facades\Schema;
function boot()
{
Schema::defaultStringLength(191);
}
Library generating wrong url for media files
It should generate url as http://localhost/mediable_test/public/storage/media/95510839133c8100288fbf061548acf3.jpg but it is generating http://localhost/mediable_test/public/storage/storage/media/95510839133c8100288fbf061548acf3.jpg.
uneccessary including two "storage" included in url.
my code is as
for adding media
$user = \App\User::first();
$defaultImage = new \Symfony\Component\HttpFoundation\File\File(storage_path("app/file.jpg"));
$thumbnail = \MediaUploader::fromSource($defaultImage)
->toDestination('public', 'media')
->useHashForFilename()->onDuplicateIncrement()
->upload();
$user->attachMedia($thumbnail, 'thumbnail');
and for getting url
$user = \App\User::first();
$thumbnail = $user->firstMedia('thumbnail');
$url = $thumbnail->getUrl();
//$url value coming as http://localhost/mediable_test/public/storage/storage/media/95510839133c8100288fbf061548acf3.jpg.
Using default filesystem config
Hello,
Thank you for this fantastic package!
I have run into a Sql Query exception and I am not sure if it is actually a bug or if I am doing something wrong on my end. When attempting to run $model->attachMedia($media, 'tag');
I get this error:
Illuminate\Database\QueryException with message 'SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "order"
LINE 1: select `tag`, max(`order`) as aggregate from "mediables" whe...
^ (SQL: select `tag`, max(`order`) as aggregate from "mediables" where "mediable_type" = App\Author and "mediable_id" = 1 and "tag" in (headshot) group by "tag")'
This only happens when using Postgres; it works fine when I try it with Mysql. Am I doing something wrong?
`
[ErrorException]
The use statement with non-compound name 'MediaUploader' has no effect
`
laravel: 5.4
I have this code in my controller:
$media = null;
if ($request->hasFile('header_picture')) {
$media = MediaUploaderFacade::fromSource($request->file('header_picture'));
$media
->toDestination('public', Event::DIR_EVENT_HEADER_PICTURES)
->upload();
}
$event = Event::create(...);
if (isset($media)) {
$event->attachMedia($media, ['original']);
}
My problem is that the type of $media is NOT of type Media but of type MediaUploader and this crashes here: https://github.com/plank/laravel-mediable/blob/master/src/Mediable.php#L479 as it is trying to convert an object into an array.
Am I doing something wrong or is this a bug?
current the are three config for on_duplicate
the replace is first delete the finded record and then upload again
i just want return the find record,how to carray out this?
I run into a duplicate entry error due of mixed file extensions (lower case vs. upper case):
If I upload an image on my iPhone, the file extension willl be ".JPG". If I upload the same image with lower case extension, the above error occurs.
Is there a way to "normalize" (i.e. lower case the extension) the filename to use?
Hi,
Came across your package and I have to say it has been a time save when it comes to uploading media files for different models. Many thanks for that.
I have a small question, I am trying to generate thumbnail for images that are uploaded and the intervention image class is my go to class when resizing images. While I can write the code to generate the thumbnails to individual folders / disks, is there a way I can tap into this using your package?
For example when uploading files, the fromSource method is used. Is there a method that I can use to upload a generated thumbnail e.g MediaUploaded::fromFile($thumbnail)->upload(). $thumbnail coming from something like $thumbnail = Image::make('foo.jpg')->resize(300, 200);
Any thoughts would be great!
Thanks
Emmanuel
public function create($source)
{
if ($source instanceof SourceAdapterInterface) {
return $source;
} elseif (is_object($source)) {
$adapter = $this->adaptClass($source);
} elseif (is_string($source)) {
$adapter = $this->adaptString($source);
}
if ($adapter) {
return new $adapter($source);
}
throw MediaUploadException::unrecognizedSource($source);
}
Hello to all watchers and contributors (paging @sebdesign),
With the new year approaching, I think it is time to start planning the next major version of this package. Most pressingly, with PHP 5.6 passing into security-only support tomorrow night, I think it is time to drop support for PHP 5.x branch and fully embrace the new features of PHP 7.x. I will be working on this over the next few weeks, as I have time.
A new major version presents an opportunity to add any number of other changes that we want to the codebase. So I would like to ask if there are any new features that should be incorporated into the package at the same time. Is there anything that you would like to see built into the package? Are there any methods that should really be moved or renamed? Noticed any code smells that I overlooked? Now is the time to ask.
Feel free to make any suggestions in this thread. Pull Requests also very much welcome!
I think all we'd need to do is change
public function upload(?Media $media)
and if it's supplied, use that model instead of the result of makeModel().
Does that sound like a reasonable thing to do?
Hello!
Sorry for disturbing you with such a trivial matter and thanks in advance for all the hardwork put into this package. Maybe I am reading the documentation sideways, but ive tried everything to no avail.
Essentially I am trying to query Media::whereBasename('abc.jpg'); and then ->move('new_directory')
But I keep getting Call to undefined method move()
I am using:
use Plank\Mediable\Media;
What am I missing?
Firstly, i wanna say thank for fantastic package.
I would like to ask how i can build media management interface like in admin for plankdesign.com.
Thanks
Hi,
thanks for the great package. I'm wondering if there is a way for me to store both the original filename and a hashed filename?
thanks
Hello guys. First, thanks for the package.
I'm interested if there is a way of chunked file upload. It is useful when you have realy large file and sometimes filesystem doesn't really want to work with large ones.
Planning to add support for Intervention manipulations while uploading images.
Currently considering an API like the following:
MediaUploader::fromSource('example.jpg')
->applyManipulations(function(Image $image) {
$image->resize(300, null);
}, $quality = null)
->upload()
Hi!
When I want to upload and change the file name with the "withFilename()" method, it throws me this error:
Call to undefined method Plank\Mediable\MediaUploader::withFilename()
Did I miss something? Some "use" or something else?
Trying to save the image on S3 bucket, here's the error.
$jpg = Image::make('https://www.plankdesign.com/externaluse/plank.png')->encode('jpg');
MediaUploader::fromString($jpg)->upload();
"plank/laravel-mediable": "^2.5",
"league/flysystem-aws-s3-v3": "^1.0",
"intervention/image": "^2.4",
"laravel/framework": "5.5.*"
What can I do?
config/mediable
'default_disk' => 'uploads',
'allowed_disks' => [
'uploads',
],
File system:
'uploads' => [
'driver' => 'local',
'root' => storage_path('app/uploads'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
Code to Import File
$disk=Storage::disk('local');
$path = 'uploads\about-img.jpg';
$media = MediaUploader::importPath($disk,$path);
dd($media->getUrl());
migrate in laravel 5.3 error use package
[Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (SQL: alter table media
add uniq
ue media_disk_directory_filename_extension_unique
(disk
, directory
, filename
, extension
))
[PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes
There is an issue with Plank\Mediable\Mediable::detachMediaTags()
because it attempts to invoke an undefined method getForeignKey()
which leads to error:
Call to undefined method Illuminate\Database\Query\Builder::getForeignKey()
.
This function is also called in vendor/plank/laravel-mediable/src/Mediable.php:79
.
Potentially the other function should called instead: Illuminate\Database\Eloquent\Relations\BelongsToMany::getQualifiedForeignKeyName()
When I run getUrl() function on Laravel 5.1 with local file-system and s3 as well I get following error.
$file_url = $media->getUrl();
BadMethodCallException in PluggableTrait.php line 85:
Call to undefined method League\Flysystem\Filesystem::url
Is there any previous version that will work fine with Laravel 5.1?
Laravel 5.4, replace media, via config/mediable.php
'on_duplicate' => Plank\Mediable\MediaUploader::ON_DUPLICATE_REPLACE,
From controller:
$media = MediaUploader::fromSource($file)->
toDestination('public', $path)->
upload();
I also tried forcing replace:
$media = MediaUploader::fromSource($file)->
toDestination('public', $path)->
onDuplicateReplace() ->
upload();
Either method, when file uploaded after first time, created_at value in database table media changes. Unless I am missing something, only updated_at should change?
Hi,
When I want upload a file, I have this error : Could not recognize source, 'poster_3_fury_road_mad_max_by_cesaria_yohann-d8rd450.jpg' provided.
My code, is the exemple code from documentation:
$media = MediaUploader::fromSource($request->input('media'))
->toDestination('public', 'thumbnails')
->upload();
One idea ?
Thank you.
I'm trying to figure out a way to update a saved media.
Relations can be updated, but not the base file.
Am-I right ?
Is it possible to change the default table names from 'media' and 'mediables' to something else?
your package allows versatile usages, I'm justing missing a "sortable" on Mediables grouped by tags.
That would allow even more use cases.
hi
after attaching some media to a model how can I retrieve the media url
$files = $request->file('files');
foreach ($files as $file) {
$media = MediaUploader::fromSource($file)->upload();
$task->attachMedia($media,'image');
}
and here too
$tasks = Task::withMedia('image')->get();
Hey @frasmage and community,
thank you very much for this awesome package. I really like the lightweight approach.
I have a question regarding the upload of files - i couldn't find anything in the docs about this issue:
In my API I upload the files via Base64
encoded strings. Is there a convenient way to automatically create a file based on the Base64
string of a file?!
Cheers and thank you!
I get this when running the migrations:
[Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (SQL: alter table media
add u
nique media_disk_directory_filename_extension_unique
(disk
, directory
, filename
, extension
))
[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes
Something with this line;
$table->unique(['disk', 'directory', 'filename', 'extension']);
Hi!
I'm building a media manager for a project where users can upload images and attach them to posts, and laravel-mediable is great for that requirement. However, is there a way for the users to see only their uploaded images?
What I was thinking is to modify the media table and add a foreign key to the users table. What I don't know is how to have the user_id inserted together with the rest of the media details.
Any suggestions on how to achieve this?
Thanks.
I have already uploaded files using elfinder. To link to db, I used MediaUploader::importPath.
But, when trying to associate the same file to another model or during model update, I am getting 'Duplicate Entry Error".
Tried but not working.
'on_duplicate' => Plank\Mediable\MediaUploader::ON_DUPLICATE_REPLACE,
`
public function attachMedia($model, $filename, $attribute) {
$media = MediaUploader::importPath($this->disk, $filename);
if ($model->hasMedia('featured')) {
$model->syncMedia($media, [$attribute]);
} else {
$model->attachMedia($media, [$attribute]);
}
}
How can I check media existence before
$media = MediaUploader::importPath($this->disk, $path);
I get the same error when using this command section
up class :
use MediaUploader;
$media = MediaUploader::fromSource($request->file('image'))
->setDirectory('/avatar/demo')
->setOnDuplicateBehavior(Media::ON_DUPLICATE_REPLACE)
resuft => Undefined class constant 'ON_DUPLICATE_REPLACE'
Please use strtolower() when comparing.
Hey guys,
I try to upload files like this
$file2 = MediaUploader::fromSource(Input::file('file2'))->useHashForFilename()->toDestination('uploads', '')->upload();
$entry->attachMedia($file2, 'file2');
This works for files that have no whitespace. However when a file is named e.g. Bildschirmfoto 2016-12-28 um 15.25.17 it throws an error:
Hi,
I call package with use Plank\Mediable\MediaUploader;
, but I have this error Non-static method Plank\Mediable\MediaUploader::fromSource()
.
One idea ?
Thank you.
I'm working on 3 orther folder servers
Backend: domain a == api
frontend: domain b == call api
media : domain c ?
$media->getUrl(); // errors url
Help me !
Good morning to everybody, sorry for my English.
When i make a request the system answer the message in object. Input::file('file') it's the correct file. Why?
Hi,
First, I love this package - it's fantastic and very easy to use. But I'm a little bit confused about how to manipulate an image while uploading it (e.g. size it down to a max. resolution). I'm also using the very popular intervention image library, so this one can be used for the file compression.
So, what's the best way to do this?
I know, I could upload the file using the Image:Class of intervention and put the image string to the media class (fromString), but doing so I'll pass all the validation stuff supported by it.
Regards,
Marc
Hey,
I started using this cool package and faced with some problem, I sew in documentation that there is console command to add to database all files but I have not did it so I got error "Call to a member function delete() on null" in MediaUploader.php line 661
Its the error inside private function deleteExistingMedia(), current code is
Media::where('disk', $model->disk)
->where('directory', $model->directory)
->where('filename', $model->filename)
->where('extension', $model->extension)
->first()->delete();
It can be changed maybe this way
$media = Media::where('disk', $model->disk)
->where('directory', $model->directory)
->where('filename', $model->filename)
->where('extension', $model->extension)
->first();
if($media){
$media->delete();
}
to check for first if file is in database to not get such error
Regards,
Giorgi Chumburidze
Hi,
I've tryed to extend the Media class with an own one with more functionality (i.e. storing external meta data like the image auhor, ...). So I created a new class:
class MetaMedia extends Media
I've configured (mediable.php) it like:
'model' => \App\MetaMedia::class
After that, I got the following error:
Table 'xyz.meta_media' doesn't exist
So I've included the following line in my model:
protected $table = 'media';
After that, I got:
Column not found: 1054 Unknown column 'mediables.meta_media_id' in 'field list' (SQL: select media
.*, mediables
.mediable_id
as pivot_mediable_id
, mediables
.meta_media_id
as pivot_meta_media_id
, mediables
.tag
as pivot_tag
, ...
What to do now?
Regards,...
Hi,
I try to find a method to get only one media on posts
collection and not all media attach on each post.
For exemple :
A post has many media, all with same tag. I wanna get only one of them. I suppose we need to use the join
method, but how ?
Now a use $posts = Post::with('media')->get();
, but I dont wanna all media.
Thank you.
Kindly attach the trait for the model as well in read me file here. Simply calling attachMedia() doesn't work.
class Post extends Model
{
use Mediable;
// ...
}
Hi,
I do not put up a mutator to update the filename
before the record in the database.
One can not use the mutators?
Thank you.
Hi,
Following on from the Postgres support question, will this package work well with MS SQL server?
Thanks,
Nhg
I was reading the Docs, and I found this to have many great features. One thing I didn't see, image manipulation, or at least image resizing to thumbnails, like what Wordpress do.
Intervention/image is a very nice image manipulation library. It would be great if it will be integrated with laravel-mediable.
public function isPubliclyAccessible()
{
return strpos($this->getAbsolutePath(), public_path()) === 0;
}
Symbolic link should be considered.
See more: https://laravel.com/docs/5.3/filesystem#the-public-disk
Is there a minimum supported version of MySQL for this package? Running 5.6.28 I get the following error when attempting to attach a Mediable:
SQLSTATE[42000]: Syntax error or access violation: 1140 Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause (SQL: select max(
order) as aggregate from
mediainner join
mediableson
media.
id=
mediables.
media_idwhere
mediables.
mediable_id= 3 and
mediables.
mediable_type= App\Tower and
tag= thumbnail order by
order asc)
It there an easy way get the name of the original file name (i.e. what the uploading user named the file) yet still save the file on disk with a hashed name?
Please give me example to upload new image with another sizes
if (!$user->hasMedia('avatar_' . $width . 'x' . $height)) {
$img = Image::make($user->firstMedia('avatar')->getUrl());
if ($crop) {
$img->fit($width, $height);
} else {
$img->resize($width, $height, function ($constraint) {
$constraint->aspectRatio();
});
}
}
$media = MediaUploader::fromSource($img)
->useHashForFilename()
->toDestination('cloud', 'user/avatars/thumb/')
->upload();
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.