Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

521
Views
Upload images using Svelte Kit Api

I'm making a file uploading API on Svelte. You send images via form-data and the API saves it locally.

This is what my API looks like:

export const post: RequestHandler = async ({ request })  => {
    const data = await request.formData();
    console.log(data)
    return { status: 200, body: "h"};
};

The request's body:

----------------------------930945094336727102920559
Content-Disposition: form-data; name="image"; filename="index.jpg"
Content-Type: image/jpeg

����       

basically this, I can not paste the rest

I just get FormData {} on the console

How can I save this image locally using node:fs or something similar

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

FormData has to be read and will not automatically be serialized. From the body it looks like the input already has a suitable name and is posted correctly, so you should be able to just read that as a File.

e.g.

import * as fs from 'fs/promises';

export const post: RequestHandler = async ({ request })  => {
    const data = await request.formData();
    const file = data.get('image') as File;
    await fs.writeFile(`D:/${file.name}`, file.stream());

    return { status: 200, body: "h"};
};
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!