Next.js Discord

Discord Forum

app doesnt work on server

Unanswered
gref9730 posted this in #help-forum
Open in Discord
Hello I created simple web where you can uplado three photos and then send them to backend which stores them in file system ... and when I start the server on my pc it works perfectly fine no matter how big the photos are (in terms of kb/mb), and when I take the project and put it on other pc and try to run the app there and try to send there some photos .. all the photos have maximally 768KB and if there are bigger photos they are cut and more of the photo is just black ...
anyone know how or why its happening and how to fix it?

im using formData object and putting the photos there as File and on backend im parsing them as base64

export async function POST(req: NextRequest): Promise<NextResponse> {
try {
const formData = await req.formData();

const photo01 = formData.get("photo_data_01") as string;

const photo02 = formData.get("photo_data_02") as string;

const photo03 = formData.get("photo_data_03") as string;


const parseBase64 = (base64String: string): Buffer | null => {
if (!base64String) return null;
const matches = base64String.match(/^data:(.+);base64,(.+)$/);
if (matches && matches.length === 3) {
const base64Data = matches[2];
return Buffer.from(base64Data, 'base64');
}
return null;
};

const photo01Buffer = parseBase64(photo01);
const photo02Buffer = parseBase64(photo02);
const photo03Buffer = parseBase64(photo03);

const dir = path.join('C:', 'Temp', 'photos');
await fs.ensureDir(dir);

const photo01Path = path.join(dir, ${log_id}_photo01.jpg);
const photo02Path = path.join(dir, ${log_id}_photo02.jpg);
const photo03Path = path.join(dir, ${log_id}_photo03.jpg);

if (photo01Buffer) await fs.writeFile(photo01Path, photo01Buffer);
if (photo02Buffer) await fs.writeFile(photo02Path, photo02Buffer);
if (photo03Buffer) await fs.writeFile(photo03Path, photo03Buffer);

5 Replies

it seems like the server have maximum amount of data transfered with formData ... is there a possible setting to change the amount possible of transfer? I created a function which console.log size in bytes of the formData object and its always the same which is 3 145 728 bytes
@gref9730 Hello I created simple web where you can uplado three photos and then send them to backend which stores them in file system ... and when I start the server on my pc it works perfectly fine no matter how big the photos are (in terms of kb/mb), and when I take the project and put it on other pc and try to run the app there and try to send there some photos .. all the photos have maximally 768KB and if there are bigger photos they are cut and more of the photo is just black ... anyone know how or why its happening and how to fix it? im using formData object and putting the photos there as File and on backend im parsing them as base64 export async function POST(req: NextRequest): Promise<NextResponse> { try { const formData = await req.formData(); const photo01 = formData.get("photo_data_01") as string; const photo02 = formData.get("photo_data_02") as string; const photo03 = formData.get("photo_data_03") as string; const parseBase64 = (base64String: string): Buffer | null => { if (!base64String) return null; const matches = base64String.match(/^data:(.+);base64,(.+)$/); if (matches && matches.length === 3) { const base64Data = matches[2]; return Buffer.from(base64Data, 'base64'); } return null; }; const photo01Buffer = parseBase64(photo01); const photo02Buffer = parseBase64(photo02); const photo03Buffer = parseBase64(photo03); const dir = path.join('C:', 'Temp', 'photos'); await fs.ensureDir(dir); const photo01Path = path.join(dir, `${log_id}_photo01.jpg`); const photo02Path = path.join(dir, `${log_id}_photo02.jpg`); const photo03Path = path.join(dir, `${log_id}_photo03.jpg`); if (photo01Buffer) await fs.writeFile(photo01Path, photo01Buffer); if (photo02Buffer) await fs.writeFile(photo02Path, photo02Buffer); if (photo03Buffer) await fs.writeFile(photo03Path, photo03Buffer);
Your server/other pc might have some sort of transfer cap
what kind of server are you using?
windows server 2019 - version 1809
is there some settings directly of the server?