Route::post('/image/{campaign}/{folder}/{filename}', function ($campaign, $folder, $filename) {
$path = "private/campaigns-images/campaign-$campaign/$folder/$filename";
if (!Storage::exists($path)) {
abort(404);
}
$file = Storage::get($path);
$mimeType = Storage::mimeType($path);
return Response::make($file, 200)->header("Content-Type", $mimeType);
})->name('image.show');
< /code>
html и javaScript
В моем фронте я пытаюсь загрузить и устанавливаю изображение в качестве фона для холста Fabric.js с использованием javaScript: < /p>
1 / 3
1, 'folder' => 'images_17', 'filename' => 'DJI_20241105104710_0123_V.JPG']) }}"
alt="Campaign Image"
style="width: 100%; max-width: 1200px; height: auto;">
< /code>
const canvas = new fabric.Canvas('canvas');
function setBackgroundImage() {
const imgElement = document.getElementById('background-image');
if (imgElement) {
imgElement.onload = function () {
fabric.Image.fromURL(imgElement.src, function (img) {
canvas.setBackgroundImage(img, canvas.renderAll.bind(canvas), {
scaleX: canvas.width / img.width,
scaleY: canvas.height / img.height
});
});
};
// If the image is already loaded (from cache), trigger onload manually
if (imgElement.complete) {
imgElement.onload();
}
}
}
window.onload = function () {
setBackgroundImage();
};
< /code>
Issue
When I try to access an image via (GET request):http://127.0.0.1:8000/admin/image/1/ima ... 0123_V.JPG< /code>
I get the response "No response data for this request" but if I click on the same link the resource is available
What I've Tried
Checked that the file exists using Storage::exists($path), and it does.
Changed the route method from POST to GET, but still no response.
Checked storage/logs/laravel.log but no related errors appear.
Tried return response('Test Response'); inside the route, but nothing is displayed..
Подробнее здесь: https://stackoverflow.com/questions/794 ... sing-an-im