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?
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:
- 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'); });
-
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']); } } }
- 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...
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.
1-11 of 11