This commit is contained in:
Rizky 2024-02-07 18:28:42 +07:00
parent e4e2ca7616
commit f1180c2966
1 changed files with 10 additions and 2 deletions

View File

@ -69,16 +69,24 @@ export const fetchViaProxy = async (
(Array.isArray(data) && data[0] instanceof File) (Array.isArray(data) && data[0] instanceof File)
) { ) {
const target = new URL(url); const target = new URL(url);
_headers["content-type"] = "multipart/form-data";
if (data instanceof File) { if (data instanceof File) {
const formData = new FormData();
formData.append("file", data);
const res = await fetch(target.pathname, { const res = await fetch(target.pathname, {
body: data, body: formData,
method: "POST", method: "POST",
headers: _headers, headers: _headers,
}); });
return await res.text(); return await res.text();
} else { } else {
const formData = new FormData();
let idx = 1;
for (const file of data) {
formData.append("file-" + idx++, file);
}
const res = await fetch(target.pathname, { const res = await fetch(target.pathname, {
body: data[0], body: formData,
method: "POST", method: "POST",
headers: _headers, headers: _headers,
}); });