update
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
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', body);
|
||||
const { fields, files } = await readFiles(event, {
|
||||
includeFields: true,
|
||||
})
|
||||
|
||||
|
||||
var formDat = new FormData();
|
||||
formDat.append('directoryName', fields.directoryName[0]);
|
||||
formDat.append('file', fs.createReadStream(files.file[0].filepath));
|
||||
// console.log('path',files.file[0].filepath);
|
||||
// console.log('text',fields.directoryName[0]);
|
||||
try {
|
||||
const data = await $fetch(`${apiBase}/uploader`, {
|
||||
method: 'POST',
|
||||
body: formDat,
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
//'Content-Type': 'multipart/form-data',
|
||||
'Authorization': `Bearer ${token}`
|
||||
},
|
||||
});
|
||||
console.log('uplodar',data);
|
||||
return data;
|
||||
} catch (error) {
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
})
|
||||
Reference in New Issue
Block a user