fix: upload file

Deskripsi:
- fix api upload file pada project dan task

No Issues
This commit is contained in:
amel
2024-09-04 11:21:42 +08:00
parent 6bebd7dbfa
commit db5d9a2d81
4 changed files with 5 additions and 13 deletions

View File

@@ -162,10 +162,9 @@ export async function POST(request: Request, context: { params: { id: string } }
if (cekFile) {
let a = 0
const root = path.join(process.cwd(), "./public/file/project/");
for (var pair of body.entries()) {
if (String(pair[0]) == "file" + a) {
if (String(pair[0]).substring(0, 4) == "file") {
const file = body.get(pair[0]) as File
const fExt = file.name.split(".").pop()
const fName = file.name.replace("." + fExt, "")
@@ -189,7 +188,6 @@ export async function POST(request: Request, context: { params: { id: string } }
// Tulis file ke sistem
fs.writeFileSync(filePath, buffer);
}
a++
}
}

View File

@@ -128,10 +128,9 @@ export async function POST(request: Request) {
}
if (cekFile) {
let a = 0
const root = path.join(process.cwd(), "./public/file/project/");
for (var pair of body.entries()) {
if (String(pair[0]) == "file" + a) {
if (String(pair[0]).substring(0, 4) == "file") {
const file = body.get(pair[0]) as File
const fExt = file.name.split(".").pop()
const fName = file.name.replace("." + fExt, "")
@@ -155,12 +154,11 @@ export async function POST(request: Request) {
// Tulis file ke sistem
fs.writeFileSync(filePath, buffer);
}
a++
}
}
return NextResponse.json({ success: true, message: "Berhasil membuat kegiatan", data: data, }, { status: 200 });
return NextResponse.json({ success: true, message: "Berhasil membuat kegiatan" }, { status: 200 });
} catch (error) {
console.error(error);

View File

@@ -111,10 +111,9 @@ export async function POST(request: Request, context: { params: { id: string } }
let fileFix: any[] = []
if (cekFile) {
let a = 0
const root = path.join(process.cwd(), "./public/file/task/");
for (var pair of body.entries()) {
if (String(pair[0]) == "file" + a) {
if (String(pair[0]).substring(0, 4) == "file") {
const file = body.get(pair[0]) as File
const fExt = file.name.split(".").pop()
const fName = file.name.replace("." + fExt, "")
@@ -149,7 +148,6 @@ export async function POST(request: Request, context: { params: { id: string } }
fileFix.push(dataFile)
}
a++
}
const insertFile = await prisma.divisionProjectFile.createMany({

View File

@@ -152,10 +152,9 @@ export async function POST(request: Request) {
let fileFix: any[] = []
if (cekFile) {
let a = 0
const root = path.join(process.cwd(), "./public/file/task/");
for (var pair of body.entries()) {
if (String(pair[0]) == "file" + a) {
if (String(pair[0]).substring(0, 4) == "file") {
const file = body.get(pair[0]) as File
const fExt = file.name.split(".").pop()
const fName = file.name.replace("." + fExt, "")
@@ -190,7 +189,6 @@ export async function POST(request: Request) {
fileFix.push(dataFile)
}
a++
}
const insertFile = await prisma.divisionProjectFile.createMany({