The fetch() operation encountered an error, with the server not receiving the request. The error message displayed is "Object2 is not iterable."

I have encountered an issue while using this code to fetch images. I keep receiving a 422 error code and the request does not seem to reach the backend. Despite trying different solutions, including using axios, the problem persist on my end while others do not face the same issue. Can someone please assist me with resolving this problem?

import axios from 'axios';
var FormData = require('form-data');
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction

export const config = {
    api: {
        bodyParser: {
            sizeLimit: '5mb', // Set desired value here
        },
    },
};
async function uploadFile(
    prompt,
    withoutbg_image_base64,
    randID,
    username,
    model_name
) {
    var formData = new FormData();
    formData.append('prompt', prompt);
    formData.append('withoutbg_image_base64', withoutbg_image_base64);
    formData.append('randID', randID);
    formData.append('username', username);
    formData.append('model_name', model_name);
    
    try {
        const response = await fetch(URL, {
            method: 'POST',
            body: formData,
        });

        const data = await response.json();

        return data;
    } catch (error) {
        console.error(error);
    }
    return {};
}

Answer №1

After some analysis, I was able to uncover the resolution. It appears that the code mentioned above is designed for compatibility with version 16 of the node, but encounters issues when used with version 18. If you are facing a similar issue, this information may be beneficial for you.

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

Automatically populate Bootstrap modal input with a value retrieved from an AngularJS controller

Can someone assist me with prefilling my form in a bootstrap modal using ng-model data? I attempted some methods but haven't been successful. Here is a link to the plunker with my code. I tried incorporating a resolve function with a $scope object ret ...

Issues with border/padding and overlay in Packery Grid Layout

After spending some time working on a grid layout using the metafizzy isotope packery mode, I have encountered a few issues. To illustrate my problem, I have provided a link to a codepen below: http://codepen.io/anon/pen/EgKdpL Although I am satisfied wi ...

Can you create asynchronous code or functions without using Web APIs at all?

Even though JavaScript is single-threaded, I can't help but wonder about a function that takes an unusual amount of time without any involvement from web APIs like this: console.log("start") function banana() { let bananaCount = 10; while (b ...

Incorporating a React component into a vanilla JavaScript document

Currently, I am working on implementing a weather widget using an npm module called . This particular module is based on React components, which is a new territory for me. I have managed to include the CDNs provided by the npm module, but I am struggling ...

Decipher the JSON data for a Facebook cover photo

I am utilizing the Facebook Graph API to retrieve the user's cover picture. By accessing the link provided at , a JSON object containing the picture link is returned. How can I fetch this link using JQuery or JavaScript? Here is my attempt: HTML: & ...

What is the best way to obtain various classed elements within a single node list?

I'm trying to select two different elements with different classes within the same node list. For example, if I could use this code: document.querySelectorAll(".a, .b"); It would mean selecting elements with the ".a" class, but also including any el ...

Issue with VueJS/Nuxt: When using this.$router.push, the wrong template is being returned to the <nuxt-link> tag

Currently, I'm developing a search feature that takes the value from a select box and sends the user to the appropriate page. However, there seems to be an issue where the wrong template is being called upon rendering, resulting in no content being di ...

What is the most effective method for enlarging elements using Javascript?

I have come across many different methods for expanding elements on webpages, such as using divs with javascript and jquery. I am curious to know what the most optimal and user-friendly approach is in terms of performance, among other things. For instance ...

Ensure that the JSON file contains values within an array of objects

Currently, I am working with JavaScript and have a JSON file containing Twitter data. Accessing the data is not an issue as I can easily retrieve it using something like: var content = data.text;, allowing me to modify a div using innerHTML. However, I am ...

IIS6 hosting a Node.js server

In my corporate environment, we are restricted to using IIS6 and cannot upgrade. I would like to run node.js within IIS6 but have found that iisnode is only compatible with IIS7. Is there an ISAPI redirect solution available that can facilitate the conne ...

Utilizing JQUERY to efficiently parse nested nodes in JSON data for Google Orgchart

I am facing an issue where I am attempting to create an array with 'v' and 'f' nodes as shown in the accompanying image. Despite having raw data that resembles what I need, I am unable to successfully split it using a jquery code snipp ...

What strategies can be utilized to address the duplication of server code in js templates?

One recurring issue I've encountered is duplicating razor code by creating javascript templates for ajax loading. This results in double the work, as changes to the serverside template also require updates to the js template. How can I avoid this dupl ...

How can I retrieve a global variable in Angular that was initialized within an IIFE?

I'm a beginner in Angular, so I ask for your patience. Currently, I am in the process of migrating an app from Asp.net MVC5 to Angular. One of the key functionalities of this application involves connecting to a third-party system by downloading a Jav ...

Modify the way the menu functions using only CSS or Javascript

Looking to update a menu using only CSS or JavaScript. The menu is designed for an e-commerce website, featuring categories with collapsed subcategories. I'd like the sub-categories to automatically expand when the page loads, eliminating the need fo ...

Is it possible to modify a hyperlink title using the named title attribute?

I am currently exploring the possibility of changing the color of a link by polling the title attribute. I have an HTML page that is generated from a script creating an accordion list of hyperlinks. I want to highlight certain hyperlinks and plan to use Ja ...

Filtering FieldSelector options in react-querybuilder: A step-by-step guide

I am currently working on a task to eliminate the fields from FieldSelector that have already been utilized. In my custom FieldSelector component, let's assume there are fields A, B, C, D, E available. If A & B have been used, they should not be ...

Attempting to retrieve data from a JSON file according to the choice made by the user in a dropdown menu

My goal is to create a user interface where users can select options from a drop-down list and receive corresponding output based on their selection. The drop-down list options are populated using data from a JSON file, and the desired output is derived fr ...

Adjust the button's width as the text changes to create a dynamic animation

I'm trying to create an animation effect where the width of a button changes whenever the text inside it is updated. I've attempted using useRef on the button itself to grab its clientWidth and then applying that value to a CSS variable in order ...

Initiating, halting, and rejuvenating a timer in JavaScript

Here is a simple code snippet where I'm experimenting with starting, stopping, and resetting a JavaScript timer. The goal is to have a timer running on a page that sends a message once it reaches the end of its countdown before restarting. The stop b ...

What are the ways to identify if a window has been refreshed or closed using JavaScript?

I've encountered this issue before, but I'm having trouble figuring it out. In my .aspx file, there is a function in the onunload body tag that refreshes the parent page. Now, I need to determine if the page has been refreshed or reloaded becau ...