I’m working on a Nextjs application that uploads files to my ftp server.
it works locally but when i deploy it in vercel it shows this error :
<code>(node:12) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
</code>
<code>(node:12) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
</code>
(node:12) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
By the way i’m using the sam node version v20
And this is the POST method:
<code>import Client from "ftp";
import { NextRequest, NextResponse } from "next/server";
export async function POST(request: NextRequest) {
try {
const formData = await request.formData();
const file = formData.get("file") as File | null;
if (!file) {
throw new Error("No file uploaded");
}
const bytes = await file.arrayBuffer();
const buffer = Buffer.from(bytes);
const c = new Client();
c.on("ready", function () {
// Change the filename as needed
c.put(buffer, "foo.txt", function (err) {
if (err) {
console.error("FTP error:", err);
throw err;
}
c.end();
});
});
const secureOptions = {
host: FTP_HOST,
user: FTP_USER,
password: FTP_PASSWORD,
port: 21,
};
c.connect(secureOptions);
return NextResponse.json({ message: "File uploaded successfully" });
} catch (err) {
console.error("Error:", err);
return NextResponse.json({ error: "errror" }, { status: 500 });
}
}
</code>
<code>import Client from "ftp";
import { NextRequest, NextResponse } from "next/server";
export async function POST(request: NextRequest) {
try {
const formData = await request.formData();
const file = formData.get("file") as File | null;
if (!file) {
throw new Error("No file uploaded");
}
const bytes = await file.arrayBuffer();
const buffer = Buffer.from(bytes);
const c = new Client();
c.on("ready", function () {
// Change the filename as needed
c.put(buffer, "foo.txt", function (err) {
if (err) {
console.error("FTP error:", err);
throw err;
}
c.end();
});
});
const secureOptions = {
host: FTP_HOST,
user: FTP_USER,
password: FTP_PASSWORD,
port: 21,
};
c.connect(secureOptions);
return NextResponse.json({ message: "File uploaded successfully" });
} catch (err) {
console.error("Error:", err);
return NextResponse.json({ error: "errror" }, { status: 500 });
}
}
</code>
import Client from "ftp";
import { NextRequest, NextResponse } from "next/server";
export async function POST(request: NextRequest) {
try {
const formData = await request.formData();
const file = formData.get("file") as File | null;
if (!file) {
throw new Error("No file uploaded");
}
const bytes = await file.arrayBuffer();
const buffer = Buffer.from(bytes);
const c = new Client();
c.on("ready", function () {
// Change the filename as needed
c.put(buffer, "foo.txt", function (err) {
if (err) {
console.error("FTP error:", err);
throw err;
}
c.end();
});
});
const secureOptions = {
host: FTP_HOST,
user: FTP_USER,
password: FTP_PASSWORD,
port: 21,
};
c.connect(secureOptions);
return NextResponse.json({ message: "File uploaded successfully" });
} catch (err) {
console.error("Error:", err);
return NextResponse.json({ error: "errror" }, { status: 500 });
}
}