<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\DB;
class HeritageImageController extends Controller
{
public function proxyImage($id)
{
$image = DB::table('world_heritage_site_images')->find($id);
if (!$image) {
return response()->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()) {
return response()->json(['error' => 'Failed to fetch image from UNESCO'], 500);
}
return response($response->body(), 200)
->header('Content-Type', $response->header('Content-Type'))
->header('Access-Control-Allow-Origin', '*');
}
}
Parent issue
#475
Overview
Create (or update)
app/Http/Controllers/HeritageImageController.phpwith aproxyImagemethod that fetches the image from UNESCO on behalf of the browser and streams it back.Implementation
Acceptance criteria
Content-Typewhen a valididis suppliedidAccess-Control-Allow-Origin: *header