hasFile does not pass validation, so it does not register
I take the screenshot and send it to the saveScreen method with the post method https://prnt.sc/Iv8GRtguBCPt output is this way, but when it comes to saving, I can't save it, I wonder exactly where I am making a mistake.
document.getElementById('screenshotButton').addEventListener('click', function() {
var currentURL = window.location.href;
var parts = currentURL.split('track_warehouse/');
var afterTrackWarehouse = parts[1];
var csrfToken = document.head.querySelector('meta[name="csrf-token"]').content;
html2canvas(document.body).then(function(canvas) {
var screenshot = canvas.toDataURL('image/png');
var formData = new FormData();
formData.append('screenshot', screenshot);
formData.append('afterTrackWarehouse', afterTrackWarehouse);
formData.append('_token', csrfToken);
var xhr = new XMLHttpRequest();
xhr.open('POST', '/save-screenshot', true);
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
console.log('Ekran görüntüsü başarıyla kaydedildi ve gönderildi.');
} else {
console.log('Ekran görüntüsü kaydedilirken bir hata oluştu.');
}
}
};
xhr.send(formData);
});
});
</script>
try {
$product = OrderExit::where('order_uuid', $request->input('afterTrackWarehouse'))->firstOrFail();
if ($request->hasFile('screenshot')) {
$screenshot = $request->file('screenshot');
$path = $screenshot->store('/screenShot', 'local');
$product->screenshot_product = $path;
$product->save();
return response()->json(['message' => 'Resim başarıyla kaydedildi.'], 200);
} else {
return response()->json(['message' => 'Resim Kaydedilmedi'], 400);
}
} catch (Exception $exception) {
dd($exception);
//return response()->json(['message' => 'Resim Kaydedilmedi'],400);
}
I tried to send the photo by wrapping it in form data but it did not work.