解决这个问题的一种方法是创建自己的缓存系统。如果本地文件系统上不存在该图像,请将其从Dropbox中拉出,然后将其保存到本地文件系统并提供服务。如果它已经存在于本地文件系统中,只需从本地文件系统提供服务。
1条路线
从他们自己的路线服务图像。
Route::get('images/{filename}', [
'uses' => 'ImageController@getImage'
]);
2控制器
检查本地文件系统以查看该文件是否已存在,否则从Dropbox中提取该文件并将其存储在本地文件系统中。
<?php
namespace App\Http\Controllers;
class ImageController extends Controller
public function __construct()
{
parent::__construct();
}
public function getImage($filename)
{
// If the file doesn't exist
if(!file_exists('/path/to/' . $filename)) {
// 1. Get the image from dropbox
// 2. Save the image to local storage
}
// 3. Serve the image from local storage
}
}