This commit is contained in:
HAM!DREZA
2024-06-13 16:49:34 +03:30
parent c8bfc3c177
commit 2886e999f1
7 changed files with 149 additions and 50 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ export default defineEventHandler(async (event) => {
setCookie(event, 'token', data.token, {
httpOnly: true,
secure: true,
maxAge: 60 * 60 * 24 * 7, // 1 week
maxAge: 60 * 60 * 24 * 7 , // 1 week
path: '/'
})
return data;
+24 -25
View File
@@ -1,33 +1,32 @@
import { readFiles } from 'h3-formidable'
import FormData from 'form-data';
import fs from 'fs';
export default defineEventHandler(async (event) => {
const { public: { apiBase } } = useRuntimeConfig();
const token = getCookie(event, 'token');
const body = await readBody(event);
console.log(body);
// const body = await readBody(event);
// console.log('body', body);
const { fields, files } = await readFiles(event, {
includeFields: true,
})
let formDat = new FormData();
formDat.append('file', fs.createReadStream(files.file[0].filepath));
formDat.append('directoryName', fields.directoryName[0]);
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;
const data = await $fetch(`${apiBase}/uploader`, {
method: 'POST',
body: formDat,
headers: {
'Accept': 'application/json',
'Authorization': `Bearer ${token}`
},
});
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: '/'
// })
// }
console.log('error', error);
return error;
}