You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat: Implement proxyImage method in HeritageImageController #471
Create (or update) app/Http/Controllers/HeritageImageController.php with a proxyImage method that fetches the image from UNESCO on behalf of the browser and streams it back.
Implementation
<?phpnamespaceApp\Http\Controllers;
useIlluminate\Http\Request;
useIlluminate\Support\Facades\Http;
useIlluminate\Support\Facades\DB;
class HeritageImageController extends Controller
{
publicfunctionproxyImage($id)
{
$image = DB::table('world_heritage_site_images')->find($id);
if (!$image) {
returnresponse()->json(['error' => 'Image record not found'], 404);
}
$response = Http::withHeaders([
'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
])->get($image->url);
if ($response->failed()) {
returnresponse()->json(['error' => 'Failed to fetch image from UNESCO'], 500);
}
returnresponse($response->body(), 200)
->header('Content-Type', $response->header('Content-Type'))
->header('Access-Control-Allow-Origin', '*');
}
}
Acceptance criteria
Returns the image binary with correct Content-Type when a valid id is supplied
Returns 404 when no record exists for the given id
Returns 500 when the upstream UNESCO request fails
Activity