Skip to content

Req File Always undefined #1286

Answered by bhrtsnegi
yassineultimate asked this question in Q&A
Discussion options

You must be logged in to vote

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 a uri field
name: "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": "…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by yassineultimate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
2 participants
Converted from issue

This discussion was converted from issue #1285 on November 17, 2024 10:39.