我知道如何使用Laravel从本地存储上传文件到AWS。但我想直接从外部URL上传文件到AWS,而不需要下载。
您有什么建议,如何实现这一点?
您有什么建议,如何实现这一点?
我最终使用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');
接受的答案依赖于另一个库。您可以在没有 Intervention Image 库的情况下完成它。以下是您可以完成此操作的方法-
$url = 'https://remote.site/photo/name.jpg'
$contents = file_get_contents($url);
$name = substr($url, strrpos($url, '/') + 1);
Storage::put($name, $contents);