classic-o / nova-media-library

Media Library for admin panel "Laravel Nova"
MIT License
157 stars 66 forks source link

Programatically add media to the media library #7

Closed cgarofalo closed 5 years ago

cgarofalo commented 5 years ago

Hi, I am looking import media into the media manager from an API source. There doesn't seem to be any documentation on how to programatically add media. Any ideas? Thanks in advance.

classic-o commented 5 years ago

Hi, My package works only with local files and s3. Can you give me example, what you want. May be will do this :) If I understand correctly, you want upload files by remove url to the library?

cgarofalo commented 5 years ago

Hi, Thanks for the quick response.

I'm using the ResourceSpace API. I can get the file paths from the API and I'm looking to save a copy of that file to the Media Library. Is that possible?

I figured something like

$media = new Media();
$media->save();

I feel like there's a way to do this?

Edit: I'm saving the files locally.

classic-o commented 5 years ago

You want to do this? Media::upload($remote_url) I think I can do it. Maybe this week or next.

cgarofalo commented 5 years ago

Yes! That would be fantastic. Could be a $remote_url or even a $path or $file. Basically feed it a file, and it gets saved to the Media Library. Thanks a bunch!

classic-o commented 5 years ago

Now, If you have $file, you can use internal existing capabilities Post file to this route /nova-vendor/nova-media-library/upload

Package routing https://github.com/classic-o/nova-media-library/blob/master/routes/api.php Controller (upload method) https://github.com/classic-o/nova-media-library/blob/master/src/Core/Controller.php

cgarofalo commented 5 years ago

I did see that, but I kept getting a 500 error when I tried posting to that route. I must have been doing something wrong.

classic-o commented 5 years ago

Added in 0.4.0

cgarofalo commented 5 years ago

@classic-o Thank so much! You're the best!