This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

Just browsed through the plugins for a second time. Could be that I am overlooking something; However, I am looking for a way to extend the media manager to upload image/video via api. Currently, I have the plugin API builder installed. Any suggestions on how to extend media manager?

U need an endpoint to handle the upload.

Is there a way to bring the media manager database? Only see how to do it with plugins.

What do you want to do?

Media manager has no database. It manages media on filesystem

I want to upload video to use with blog post and other places on the site from api. Im not sure of where to POST these files to.

u need and endpoint to handle the upload. U said u installed API builder, so enable use custom routes in the routes config, and then:

  1. Add the following to rainlab/blog/classes/RoutesHelper.php
    <?php
          Route::group(['prefix' => 'api/v1', 'middleware' => ['throttle:60,1']], function() {
                Route::post('addMedia', 'rainlab\blog\controllers\Api\MediaController@upload');
         });
  2. Create file MediaController.php in rainlab/blog/controllers/Api/ with the following contents:

    <?php namespace Rainlab\Blog\Controllers\Api;
    use Illuminate\Support\Facades\Storage;
    use Illuminate\Support\Facades\File;
    use Illuminate\Http\Request;
    class MediaController{
    
        public function upload(Request $request)
        {
                if($request->has('media')){
    $media = $request->file('media');
                Storage::disk('local')->put('/media/'.$media->getClientOriginalName(),  File::get($media));
    
                $response = [
                        'statusCode' => 201,
                        'message' => 'Uploaded',
                        'data' => $media->getClientOriginalName()
                ];
                return response()->json($response, $response['statusCode']);
                }
                else {
                        $response = [
                                'statusCode' => 500,
                                'message' => 'Error',
                                'data' => []
                        ];
                        return response()->json($response, $response['statusCode']);
                }
         }
    }
  3. Then send a post request to http://localhost/api/v1/addMedia containing form data with media key pointing to the image/video to upload

Absolutely wonderful! Thanks. Got a 201 back for images and movies this is great! Now on to figuring out how to route to folders...

What do you want to accomplish?

Having the ability to upload videos to designated folder or subfolder within file manager with/ or without permissions, and getting the url for the video returned in the response. Then the url could be used for embedding with post or to a page. That's the immediate need. Hopefully someone with a lot more knowledge can develop a robust plugin for media management. Like getting contents of directory, etc.

I will look into it

1-11 of 11

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.