Good day,
I am follow the react native course and making sure that it will work on web browsers.
I am getting 400 bad request from backend. Error is “images” not allowed
The browser is sending base64 images that causes the error.
IOS and android sending file:// which is accepted by the backend.
I already tried adding base64 to false but still not working on web
const result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.Images,
base64: false,
quality: 0.5,
});
Here is the code that calls the API
const addListing = (listing, onUploadProgress) => {
const data = new FormData();
data.append("title", listing.title);
data.append("price", listing.price);
data.append("categoryId", listing.category.value);
data.append("description", listing.description);
listing.images.forEach((image, index) => {
data.append("images", {
name: "image" + index,
type: "image/jpeg",
uri: image,
});
});
// if (listing.location)
// data.append("location", JSON.stringify(listing.location));
return client.post(endpoint, data, {
onUploadProgress: (progress) =>
onUploadProgress(progress.loaded / progress.total),
});
};
Please help me fix the problem. Do I need to update the backend provided by the lesson?