I’m using React Native with Expo SDK 54, and I have an API client built with Axios.
All my normal JSON requests are encrypted before being sent to a .NET 6 backend. When I send a normal JSON body, my encryption works correctly, but when i use formData - it does not:
const client = axios.create({
baseURL: apiUrl,
});
client.interceptors.request.use(async (config) => {
// Add tokens
config.data = await encrypt(config.data);
if (config.data instanceof FormData) {
return config;
}
if (config.data) {
config.headers["Content-Type"] = "application/json";
}
return config;
});
const formData = new FormData();
formData.append("file", {
uri: file.uri,
name: "test.jpg",
type: "image/jpeg",
});
**
How can I encrypt a request body that contains FormData (multipart/form-data) in React Native?**
Is it even possible to encrypt and then decrypt FormData, or do I need to use another approach?
Specifically:
Should I encrypt only JSON metadata and send the file unencrypted?
Should I avoid FormData entirely if encryption is required?
Is there a correct way to encrypt multipart/form-data in React Native?