Move images from old server to s3 from url

Posted 1 year ago by eddieace


I'm trying to write a script where I'm trying to move images from an old server to s3. Is it possible to do by downloading the image from an url?

For example.

$companies = Company::all();

$companies->each( function ($company) {

    //some method to download file
    $file = download($company->logo);

    //Store on s3
    $filename = $file->storeAs('images', uniqid('img_') . "." . $file->guessClientExtension(),'s3');

    //Get the new path
    $new_path = Storage::disk('s3')->url($filename);

    //save the new path to logo
    $company->logo = $new_path;
    //save the new path

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.