The Rsuite Uploader is refusing to transfer the file to the Express server

For my project, I am utilizing an Uploader component from RSuite to upload images to the Express server:

<Uploader action={process.env.REACT_APP_API_URL + '/loadMap'} draggable headers={{Authorization: 'Bearer ' + localStorage.getItem('token')}} name="map">
    <div style={{ width: '100%', height: 300, display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
        <span>Click or Drag map image to this area to upload</span>
    </div>
</Uploader>

Although the request reaches the Express server when I upload an image, I am unable to locate the content of the uploaded image. In the IncomingMessage Request, I cannot find attributes like 'files', 'file', or any other containing the picture's content:

exports.loadMap = async (req, res, next) => {
    let mapContent = req.body.map;
    let mapFile = req.file;
}

Could someone guide me on how to retrieve and save this content on the server? Your help is greatly appreciated. Thank you.

Answer №1

After much searching, I finally discovered the solution to my problem. It turns out that the issue was in NodeJS rather than RSUITE like I initially thought. I needed a package to read data from a form, so I ended up using the formidable package from npm:

exports.loadMap = async (req, res, next) => {
    const formidable = require('formidable');
    const uploadFolderTemp = path.join(__dirname, "..", "images", 'temp');

    var form = new formidable.IncomingForm({uploadDir: uploadFolderTemp});
    form.parse(req, async (err, fields, files) => {
        const fileExtension = '.' + files.file.originalFilename.split('.')[1];
        fs.rename(files.file.filepath, UPLOAD_FOLDER + '/' + FILENAME + fileExtension, async (err) => {
            next();
        });
    });
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

There are no documents found with the specified UUID in MongoDB

I have been attempting to retrieve a specific document from MongoDB that includes the field "ownerId" containing a binary UUID. In the Mongo console, when I run the command db.dataset.find({ownerId: BinData(3,"ZQ6EAOKbQdSnFkRmVUUAAA==")}).pretty() The ou ...

Having difficulty retrieving information from Redux store

In my project, I utilize the Redux store to manage data. Through Redux-DevTools, I can observe that initially the data is null but upon refreshing the page, the data successfully populates the store. However, when attempting to retrieve this data within on ...

Issue in CakePHP after modifying the directory of Index

I'm currently working on a project using CakePHP and have come across an issue. Our team developed an Ajax function that sends data to a PHP function responsible for adding a folder (known as "ordner" in German) to the database. Initially, everything ...

Including v-menu in a button causes it to vanish in Vuetify

I am facing an issue with my stepper. Specifically, in step 3, I am trying to add a v-menu to a button but when I do so, the button disappears. Below is the code snippet causing the problem: <template> . . . . <v-stepper-step :complete="e6 > ...

Trouble arises with kids when trying to adjust the display to block mode

I need to set all the div elements inside the div with id "editor" to display as block. However, when I change the display property of the div with id "editor", only that specific div's display is affected, while everything else inside the div becomes ...

Sending data as a string in an AJAX request

I have been struggling with this coffeescript function that controls dynamic select boxes. I am trying to pass the content of "modelsSelect" to another script, but for some reason, it's not working as intended. customScript.coffee dynamicSelection = ...

Challenges faced with dividing a string in JavaScript

Having trouble splitting a string in JavaScript, I can't seem to make it work. This is the JavaScript code I am using: var str = 'TestApplication20 Application200'; var parts = str.match(/(\d+)(\D.+)/).slice(1); var id = parts[0 ...

Real-time Dropdown Updating in PHP

I apologize if this question has been addressed previously, but I have attempted a search and have not found answers in other posts. The responses I did come across did not pertain to my specific question (which mostly revolved around dropdowns fetching re ...

Is there a way to utilize jQuery for parsing the XML file?

When trying to parse the file, the value for "name" in the code is always an empty string. Here is my XML data: <row> <id>1</id> <AnrufenZahl>64</AnrufenZahl> <NameOperator>Ioan</NameOperator> </row> ...

Is it better to conceal modals or completely eliminate them from the DOM when working with React?

I am currently developing a React application that involves multiple modals, with only one active at a time and no nested modals. I am torn between two approaches for handling the showing and hiding of these modals: The first approach involves having a b ...

Telegram: verification key mismatch detected

I am currently facing an issue with implementing a Telegram PHP example using JavaScript. The hashes do not match, even after running the example's php code which also resulted in failure with identical hashes. I have tried adjusting my bot settings b ...

Swap out a particular component during the testing phase

Currently, I am running tests on my React-Redux application using Jest. Within my API calls, I have integrated a fetch module called cross-fetch. However, I am looking to substitute this with fetch-mock. Take a look at my directory structure: Action.js i ...

Converting array elements to strings when extracting in JSON with JavaScript

I am working with a Json document that looks like this: { "_id": "13fee4aad95c7f822c0b559bd8d09fb0", "_rev": "5-336dea3680af3e7ec0de29369be90b09", "attributeCollection": { "attributeArray": [ { "name": "Web Issue", "val ...

Updating user's password securely with bcrypt encryption using the PUT request method in an application utilizing mysql2, sequelize, and express framework

I'm currently working on implementing a feature that allows users to update their details. Everything seems to be functioning correctly except for changing the password. When I attempt to allow users to modify their passwords, I encounter issues. Edi ...

Steps for displaying a particular slide from a thumbnail in a modal with Slick Carousel

My setup includes an array of thumbnails and a Slick Carousel within a hidden modal. Is there a way to trigger the opening of the carousel by clicking on a thumbnail, ensuring that it starts from the corresponding slide? https://i.sstatic.net/BJU2o.png ...

Execute functions upon the completion of jQuery ajax requests

I need to trigger my function loadTest() once the bootstrap dialog is fully loaded and displayed. $(".btn").on("click", function() { $.ajax({ type: "POST", url: '/echo/html/', data: { html: '', ...

Issue with the close button on ngb-alert not functioning properly

As I develop my website, I have incorporated an ngb-alert component to display an alert message to users upon login. While the alert itself is functioning properly, I have encountered an issue with the close button being misaligned, and I am struggling to ...

How can I use jQuery to set up form validation for an input textfield?

Check out this code snippet: <form data-test="loginForm-container" novalidate="" method="POST" enctype="multipart/form-data"> <div class="css-o5d3v1 e1ovefus2"> <div data-test="guestForm-email-wrapper" class="e1ovefus1 css-yjv4po e1eu3s ...

Issue: Unable to assign type 'FormDataEntryValue' to type 'string'. Type 'File' cannot be assigned to type 'string'

After retrieving data from the formData, I need to pass it to a function for sending an email. Error: The error message states that 'FormDataEntryValue' is not compatible with type 'string | null'.ts(2322) definitions.ts(119, 3): The e ...

Ways to have a list component smoothly descend when a dropdown menu is activated

I have a situation where I have a list with two buttons, and each button triggers the same dropdown content in a sidebar component. The issue is that when I click on one button to open the dropdown, the second button does not move down to make space for it ...