Move images from old server to s3 from url

Posted 1 year ago by eddieace

Hi!

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
    $company->save();
}

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

Reply to

Use Markdown with GitHub-flavored code blocks.