5

I know how to upload file from local storage to aws using laravel. But I want to upload file directly from external url to aws without downloading.

Any suggestion, how can I achieve this.

2
  • There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.I would suggest that you find a development forum (perhaps Quora?) to work out generalities. Then, when/if you have specific coding issues, come back to StackOverflow and we'll be glad to help. Commented Feb 8, 2016 at 13:36
  • Thank you @JayBlanchard but I am unable to find any link which is elaborating this and it is also not mentioned in the doc of laravel. Can you share link of some resources Commented Feb 8, 2016 at 13:42

2 Answers 2

8

I finally solved this using Intervention Image Library.

use Image;
use Storage;


$image = Image::make('url');
$image->encode('jpg');
$s3 = Storage::disk('s3');
$filePath = '/profilePhotos/'.$time();
$s3->put($filePath, $image->__toString(), 'public');

Installation instructions for Image library can be found here in the "Integration in Laravel" section.

Sign up to request clarification or add additional context in comments.

Comments

2

The accepted answer is dependent on another library. You can do it without the Intervention Image Library. Here is how you can do it-

$url = 'https://remote.site/photo/name.jpg'
$contents = file_get_contents($url);
$name = substr($url, strrpos($url, '/') + 1);
Storage::put($name, $contents);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.