Кемеровские программисты php общаются здесь
Anonymous
Работаем локально, но не работаем на производстве с ошибкой 422 Unprocessable Entity
Сообщение
Anonymous » 01 июл 2024, 19:30
Я попытался создать свой собственный парсер HAR в существующем PHP-проекте Laravel. Локально все работает отлично
har.blade.php
Код: Выделить всё
Upload HAR File
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
background-color: #f0f0f0;
}
h2 {
margin-bottom: 20px;
}
.dropzone {
width: 50%;
border: 2px dashed #007bff;
background-color: white;
padding: 20px;
border-radius: 10px;
}
.dz-message {
color: #007bff;
}
.dz-error-message {
color: red;
}
Upload HAR File
@csrf
Drop HAR file here or click to upload.
Dropzone.autoDiscover = false;
var myDropzone = new Dropzone("#har-dropzone", {
url: "{{ route('har.upload') }}",
paramName: "file",
maxFiles: 1,
acceptedFiles: ".har",
headers: {
'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').getAttribute('content')
},
init: function() {
this.on("success", function(file, response) {
window.location.href = response.redirect_url;
});
this.on("error", function(file, message) {
if (!file.type.includes("har")) {
var errorMessage = document.createElement('div');
errorMessage.className = 'dz-error-message';
errorMessage.innerText = 'Invalid file type. Only HAR files are accepted.';
file.previewElement.appendChild(errorMessage);
setTimeout(function() {
location.reload();
}, 2000);
}
});
this.on("maxfilesexceeded", function(file) {
this.removeAllFiles();
this.addFile(file);
});
}
});
document.body.ondrop = function(e) {
e.preventDefault();
e.stopPropagation();
var files = e.dataTransfer.files;
if (files.length > 0 && files[0].type.includes("har")) {
myDropzone.addFile(files[0]);
} else {
alert('Invalid file type. Only HAR files are accepted.');
setTimeout(function() {
location.reload();
}, 2000);
}
};
document.body.ondragover = function(e) {
e.preventDefault();
e.stopPropagation();
};
Другой файл PHP:
Код: Выделить всё
Подробнее здесь: [url]https://stackoverflow.com/questions/78693322/working-locally-but-failing-on-production-with-422-unprocessable-entity-error[/url]
1719851410
Anonymous
Я попытался создать свой собственный парсер HAR в существующем PHP-проекте Laravel. Локально все работает отлично [img]https://i.sstatic.net/HkoCk4Oy.png[/img] har.blade.php [code] Upload HAR File body { font-family: Arial, sans-serif; margin: 0; padding: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; background-color: #f0f0f0; } h2 { margin-bottom: 20px; } .dropzone { width: 50%; border: 2px dashed #007bff; background-color: white; padding: 20px; border-radius: 10px; } .dz-message { color: #007bff; } .dz-error-message { color: red; } Upload HAR File @csrf Drop HAR file here or click to upload. Dropzone.autoDiscover = false; var myDropzone = new Dropzone("#har-dropzone", { url: "{{ route('har.upload') }}", paramName: "file", maxFiles: 1, acceptedFiles: ".har", headers: { 'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').getAttribute('content') }, init: function() { this.on("success", function(file, response) { window.location.href = response.redirect_url; }); this.on("error", function(file, message) { if (!file.type.includes("har")) { var errorMessage = document.createElement('div'); errorMessage.className = 'dz-error-message'; errorMessage.innerText = 'Invalid file type. Only HAR files are accepted.'; file.previewElement.appendChild(errorMessage); setTimeout(function() { location.reload(); }, 2000); } }); this.on("maxfilesexceeded", function(file) { this.removeAllFiles(); this.addFile(file); }); } }); document.body.ondrop = function(e) { e.preventDefault(); e.stopPropagation(); var files = e.dataTransfer.files; if (files.length > 0 && files[0].type.includes("har")) { myDropzone.addFile(files[0]); } else { alert('Invalid file type. Only HAR files are accepted.'); setTimeout(function() { location.reload(); }, 2000); } }; document.body.ondragover = function(e) { e.preventDefault(); e.stopPropagation(); }; [/code] Другой файл PHP: [code] Подробнее здесь: [url]https://stackoverflow.com/questions/78693322/working-locally-but-failing-on-production-with-422-unprocessable-entity-error[/url]