Logo

dev-resources.site

for different kinds of informations.

Process FormData file sent to Node server

Published at
3/19/2023
Categories
file
upload
formdata
attach
Author
brett84c
Categories
4 categories in total
file
open
upload
open
formdata
open
attach
open
Author
8 person written this
brett84c
open
Process FormData file sent to Node server

I struggled to find much online about how to simply process a FormData file (PDF, in this case) sent to a Node server to be attached to an email or used for other things. This is a very basic example but the key part is this line on the server:

Buffer.from(await file.arrayBuffer())

form.html

<form id="fileForm">
  <div>
    <label for="pdf_file">File Upload</label>
      <input type="file" name="pdf_file" />
  </div>
  <button type="submit">Send File</button>
</form>
Enter fullscreen mode Exit fullscreen mode

form.js

document.getElementById("fileForm").addEventListener("submit", (e) => {
  e.preventDefault();
  const formData = new FormData(e);
  fetch("/", {
    method: "POST",
    body: formData
  });
});
Enter fullscreen mode Exit fullscreen mode

server.js

app.post('/', async (request, response) => {
  const values = await request.formData();
  const file = values.get("pdf_file");
  const processedFile = Buffer.from(await file.arrayBuffer());
  //attach to email or do other things
};
Enter fullscreen mode Exit fullscreen mode
upload Article's
30 articles in total
Favicon
UploadThing: A Modern File Upload Solution for Next.js Applications
Favicon
NestJS - Armazenamento nas nuvens
Favicon
NestJS - criar um endpoint para upload de diversos arquivos
Favicon
NestJS - Validando o envio de arquivos
Favicon
NestJS - Armazenamento local de upload
Favicon
NestJS - criar endpoint para upload de 1 arquivo
Favicon
Next.js: Upload de imagem para a Cloudflare R2 Utilizando Presigned URL
Favicon
A file uploader built with shadcn/ui and react-dropzone
Favicon
Elevate Your GraphQL API: Mastering File Uploads with Yoga GraphQL
Favicon
Mastering File Uploads in Laravel 11: A Comprehensive Guide
Favicon
How To Upload Multiple File In Laravel 10
Favicon
Different approaches to reduce AWS S3 file upload time using AWS-SDK v3 in NodeJS.
Favicon
How would you handle image upload?
Favicon
Upload File di Node JS
Favicon
Uploading Images with Node.js and React.js
Favicon
Simplifying AWS S3 File Uploads with the Android Library
Favicon
Laravel 10 Crop Image Before Upload Cropper Js
Favicon
Enhance Job Seeker Experience: Quick Image Upload for Portals
Favicon
A file upload sample with NextJs
Favicon
Azure Storage Account: Unleash the Potential of Cloud-Based Storage
Favicon
Spheron Network: Browser Upload
Favicon
Uploading files from terminal on file hosting service, and unlimited cloud storage
Favicon
Process FormData file sent to Node server
Favicon
Express file upload using Multer
Favicon
Maximize Your Client Upload Efficiency with the Bulk Upload
Favicon
Upload images in Ckeditor 5 with Laravel
Favicon
Eteot Logo
Favicon
Install & Upload WordPress Plugin
Favicon
Laravel 9 Multiple Image Upload Example
Favicon
How To Enhance JavaScript File Upload In Your Web App

Featured ones: