fix(upload): convert File to Buffer via InputFile.fromBuffer before sending to storage.createFile
node-appwrite's storage.createFile happily takes the Web File API today, but Next.js's multipart parser had already consumed the request body by the time the SDK tries to stream it again — the SDK's second pass dies with 'Unexpected end of form'. isletmem-kovakcrm's logo-actions uses the documented pattern: arrayBuffer → Buffer → InputFile.fromBuffer(buf, name). Adopting the same approach in uploadJobFilesAction. The middlewareClientMaxBodySize bump from the previous commit still matters (lifts the 10MB cap so the body even reaches us), but on its own it wasn't enough: the Web File handoff itself was broken. InputFile is exported from 'node-appwrite/file' (separate entry point — the helper isn't on the main package export).
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import { revalidatePath } from "next/cache";
|
import { revalidatePath } from "next/cache";
|
||||||
import { AppwriteException, ID, Permission, Role } from "node-appwrite";
|
import { AppwriteException, ID, Permission, Role } from "node-appwrite";
|
||||||
|
import { InputFile } from "node-appwrite/file";
|
||||||
|
|
||||||
import { logAudit } from "./audit";
|
import { logAudit } from "./audit";
|
||||||
import {
|
import {
|
||||||
@@ -99,10 +100,12 @@ export async function uploadJobFilesAction(
|
|||||||
try {
|
try {
|
||||||
for (const f of files) {
|
for (const f of files) {
|
||||||
const fileId = ID.unique();
|
const fileId = ID.unique();
|
||||||
|
const buffer = Buffer.from(await f.arrayBuffer());
|
||||||
|
const inputFile = InputFile.fromBuffer(buffer, f.name);
|
||||||
await storage.createFile({
|
await storage.createFile({
|
||||||
bucketId: BUCKETS.jobFiles,
|
bucketId: BUCKETS.jobFiles,
|
||||||
fileId,
|
fileId,
|
||||||
file: f,
|
file: inputFile,
|
||||||
permissions: filePermissions(job.clinicTenantId, job.labTenantId),
|
permissions: filePermissions(job.clinicTenantId, job.labTenantId),
|
||||||
});
|
});
|
||||||
uploadedFileIds.push(fileId);
|
uploadedFileIds.push(fileId);
|
||||||
|
|||||||
Reference in New Issue
Block a user