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 {};
}