How can I upload an image file (png, jpeg etc.) from React Native using expo to a Node server using Express?
I’m a beginner to mobile UI development and the Expo documentation didn’t help much. I also tried using multer (as explained here: File upload from React Native ( expo ) to Node ( multer )), but it didn’t work.
Any suggestion, example, or direction would be highly appreciated in this regard.
2
Answers
One potential way to handle image upload between the Expo client and the Express server is to convert the image to base64 and communicate with API. Please check the comments in the code to understand each step.
Sample code is as follows.
Expo client > index.tsx
Express server > app.ts
The full source code is available on GitHub: https://github.com/ashenwgt/react-native-expo-nodejs-express-image-upload-demo
If you want to handle image files with large sizes, you can consider resizing the image, changing the resolution, or using a different format like webp.
make sure you send a formData instead of json. the multer is working fine here is the example.
this is the middleware and controller where I get the image.