Req File Always undefined #1286
-
I have This code to uplad user table image Profile but when i upload image i get req File undefined
in backend
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Don't wrap formData in an object. Axios will automatically handle the Content-Type for multipart/form-data when FormData is passed. Also, ensure that image has properties like uri, name, and type. If you're using react-native-image-picker or similar libraries, make sure to extract the proper fields. Try This `export const updateuser = async (id: number, image: any) => { formData.append("image", { const response = await axios.put( return response.data; |
Beta Was this translation helpful? Give feedback.
Don't wrap formData in an object. Axios will automatically handle the Content-Type for multipart/form-data when FormData is passed. Also, ensure that image has properties like uri, name, and type. If you're using react-native-image-picker or similar libraries, make sure to extract the proper fields.
Try This
`export const updateuser = async (id: number, image: any) => {
const formData = new FormData();
formData.append("image", {
uri: image.uri, // Ensure
image
has auri
fieldname: "uploaded_image.jpg", // Set the file name
type: image.type || "image/jpeg", // Ensure the correct MIME type
});
const response = await axios.put(
${API_URL}/image/${id}
, formData, {headers: {
"Content-Type": "…