0

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?

1
  • You should update your .NET 6 backend to support HTTPS. You wouldn't need to encrypt/decrypt your payload and it adds less overhead to your project. Side note .NET 6 has reached its end of life Commented Nov 20 at 17:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.