uploaded file path

This commit is contained in:
sandhiya-hepl
2026-07-20 14:46:54 +05:30
parent bc4c4f22ca
commit be7f3ff657
+11 -1
View File
@@ -79,8 +79,18 @@ export const adminApi = {
apiFetch('/api/auth/password', { method: 'PUT', body: JSON.stringify({ currentPassword, newPassword }) }), apiFetch('/api/auth/password', { method: 'PUT', body: JSON.stringify({ currentPassword, newPassword }) }),
upload: async (file) => { upload: async (file) => {
// Try Node API first; fall back to local data URL when server is unavailable.
try {
const form = new FormData(); const form = new FormData();
form.append('file', file); form.append('file', file);
return apiFetch('/api/upload', { method: 'POST', body: form }); return await apiFetch('/api/upload', { method: 'POST', body: form });
} catch {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = () => resolve({ url: reader.result, filename: file.name });
reader.onerror = () => reject(new Error('Failed to read file'));
reader.readAsDataURL(file);
});
}
}, },
}; };