Run With Below Command:
import React, { useState } from "react";
import ImageUploader from "react-images-upload";
const headers = {
Accept: "application/json", "Content-Type": "multipart/form-data; boundary=---------------------------974767299852498929531610575",
}
const App = () => {
const [image, setImage] = useState();
const handleSubmit = () => {
console.log(image[0]);
axios
.post(
"http://192.168.1.6:8001/api/upload",
{ image: image[0] },
{
headers: headers,
}
)
.then((response) => {
console.log(response);
});
};
return (
<div>
<ImageUploader
withIcon={true}
singleImage={true}
onChange={(p) => setImage(p.concat(p))}
imgExtension={[".jpg", ".gif", ".png", ".jpeg"]}
maxFileSize={4242880}
withPreview={true}
withIcon={true}
className="text-center"
/>
<button onClick={handleSubmit}>Upload</button>
</div>
);
};
export default App;
You are actually missing Headers "multipart/form-data"
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…