I want to ask because after a few days I haven't found a way to upload files to the API. I use suneditor for editor in my Next.js project. I want that when I upload an image, the image will be sent to the API https://api-my.com/v1/file-uploads or /file-uploads with a field that is file.
I have tried using this method, but it doesn't work.
imageUploadUrl: (file, callback) => {
const formData = new FormData();
formData.append("file", file);
axiosInstance({
url: "/file-uploads",
method: "POST",
data: formData,
headers: {
"Content-Type": "multipart/form-data",
Accept: "application/json",
},
}).then((res) => {
callback(res.data.url);
});
},
That's because that option it's waiting for a string and not a function, in any case you can use the server url
server.url/file-uploads
to upload the images.