'How to send zip Files to a Node Server via HTTP POST? (server always only receives "{}")
For my Bachelor's Thesis, I am writing a program to visualize personal data requested via GDPR Art.20. Since this kind of data is normally zipped, I need to be able to send zipped files to my node.js server. This is what I have done so far.
            async function test (element){
            let file = element.files[0];
            await base64(file);
            async function base64(file){
                let reader = new FileReader();
                reader.readAsDataURL(file);
                reader.onload = await async function () {
                    console.log(reader.result);
                    fetch('/api', {
                        method: 'POST',
                        body: reader.result,
                    })
                        .then(response => response.json())
                        .then(result => {
                            console.log('Success:', result);
                        })
                        .catch(error => {
                            console.error('Error:', error);
                        });
                };
                reader.onerror = function (error) {
                    console.log('Error: ', error);
                };
            };
        }
At this point I am only trying to console.log() my request.body, but nevertheless here is my server code:
const { response } = require("express");
const express = require("express");
const { request } = require("http");
const JSZip = require("jszip");
const app = express();
app.listen(1234, () => console.log("Listening at 1234"));
app.use(express.static("public"));
app.use(express.json({limit: "10000mb"}))
app.post("/api", async (request, response) => {
    console.log(request.body);
    response.json({status: "success33"});
});
When I log reqeust.body it is empty "{}". Does someone knows the question for this? I read a lot of threads, but none would really fit my problem.
Thanks in advance!
Solution 1:[1]
i was facing the same problem, and when i added this middleware:
import * as fileUpload from 'express-fileupload';
app.use(fileUpload({createParentPath:true})) 
the problem has gone, and i was able to get any file from req.files
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source | 
|---|---|
| Solution 1 | Alexander Bogatko | 
