Files
dlearn-front/server/api/uploader.post.js
T
2024-06-10 13:18:04 +03:30

34 lines
1.0 KiB
JavaScript

export default defineEventHandler(async (event) => {
const { public: { apiBase } } = useRuntimeConfig();
const token = getCookie(event, 'token');
const body = await readBody(event);
console.log(body);
try {
const data = await $fetch(`${apiBase}/uploader`, {
method: 'POST',
headers: {
// 'Accept': 'multipart/form-data',
'Content-Type': 'multipart/form-data',
'Authorization': `Bearer ${token}`
},
body: {
file: body.file,
directoryName: body.directoryName
}
});
console.log('uploader data', data);
return data;
} catch (error) {
console.log(error.data);
// if (error.statusCode == 401) {
// setCookie(event, 'token', '', {
// httpOnly: true,
// secure: true,
// maxAge: new Date(0),
// path: '/'
// })
// }
return error;
}
})