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