Skip to content

Import media #1150

Answered by pboivin
futurewebsites asked this question in Q&A
Sep 12, 2021 · 5 comments · 1 reply
Discussion options

You must be logged in to vote

Hi @futurewebsites,

I have a quick artisan command I adapted from MediaLibraryController::storeFile() to import a local image into the Media Library. It takes a file path but it's passed to file_get_contents(), which I believe can work with URLs.

Standard disclaimer — this was done very quickly and was only tested with the Glide media service. Your mileage may vary :)

// file: app/Console/Commands/TwillAddMedia.php

<?php

namespace App\Console\Commands;

use A17\Twill\Repositories\MediaRepository;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;

class TwillAddMedia extends Command
{
    protected $signature = 'twill:add-media {path}';

    protected $description = '

Replies: 5 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@futurewebsites
Comment options

Answer selected by futurewebsites
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants