Add files via upload

This commit is contained in:
Tomáš Dvořák
2025-05-27 07:58:51 +02:00
committed by GitHub
parent 08d51307ca
commit 23a208aa88
+8 -5
View File
@@ -747,20 +747,23 @@
} }
// Create a new headers object // Create a new headers object
const headers = new Headers(); const headers = {};
// Don't set Content-Type header manually when using FormData
// The browser will set it automatically with the correct boundary
// Add Authorization header if token exists // Add Authorization header if token exists
const token = localStorage.getItem('token'); const token = localStorage.getItem('token');
if (token) { if (token) {
headers.append('Authorization', `Bearer ${token}`); headers['Authorization'] = `Bearer ${token}`;
} }
// Note: Don't set Content-Type header when using FormData with files
// The browser will set it automatically with the correct boundary
const response = await fetch('/api/banner/update', { const response = await fetch('/api/banner/update', {
method: 'POST', method: 'POST',
headers: headers, headers: headers,
body: formData body: formData,
// Don't set Content-Type header manually when using FormData with files
// The browser will set it automatically with the correct boundary
}); });
if (!response.ok) { if (!response.ok) {