mirror of
https://github.com/Dvorinka/PPve.git
synced 2026-06-05 04:52:58 +00:00
Add files via upload
This commit is contained in:
@@ -495,7 +495,7 @@
|
||||
}, delay);
|
||||
}
|
||||
|
||||
// Override fetch to include token
|
||||
// Override fetch to include token (but NOT for FormData requests)
|
||||
const originalFetch = window.fetch;
|
||||
window.fetch = async function(resource, init = {}) {
|
||||
// Add token to headers if it's an API request
|
||||
@@ -505,8 +505,8 @@
|
||||
headers.set('Authorization', `Bearer ${token}`);
|
||||
}
|
||||
|
||||
// Set content type if not set
|
||||
if (!headers.has('Content-Type') && init.body) {
|
||||
// Only set content type if not FormData (FormData sets its own)
|
||||
if (!headers.has('Content-Type') && init.body && !(init.body instanceof FormData)) {
|
||||
headers.set('Content-Type', 'application/json');
|
||||
}
|
||||
|
||||
@@ -750,7 +750,7 @@
|
||||
console.log(key, value);
|
||||
}
|
||||
|
||||
// Create headers object
|
||||
// Create headers object - DO NOT set Content-Type for FormData!
|
||||
const headers = {};
|
||||
|
||||
// Add Authorization header if token exists
|
||||
@@ -759,12 +759,10 @@
|
||||
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
|
||||
|
||||
// Send request with FormData (browser will set correct Content-Type with boundary)
|
||||
const response = await fetch('/api/banner/update', {
|
||||
method: 'POST',
|
||||
headers: headers,
|
||||
headers: headers, // No Content-Type header!
|
||||
body: formData
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user