Summer Sale! All accounts are 50% off this week.

eddieace's avatar

Move images from old server to s3 from url

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();
}
0 likes
1 reply
jekinney's avatar

You don't need to download the file, just move it to s3. The file helper with return with the new path

Please or to participate in this conversation.