When working with Expo v47 and its corresponding React Native and TypeScript versions, FormData.append had the following typing:
FormData.append(name: string, value: any): void
An example of appending images using this code could be:
const image = {
uri: x.uri,
name: x.name,
size: x.size,
type: 'image/jpeg',
}
const formDataBody = new FormData()
formDataBody.append('data', image)
However, in Expo v48 and v49, along with their matching RN and TS versions, the typing has now changed to:
FormData.append(name: string, value: string | Blob): void
I attempted to adapt my code to match the new typing, but I encountered a Network Error when trying to POST the FormData:
try {
base64String = await FileSystem.readAsStringAsync(image.uri, { encoding: 'base64' })
} catch (error: any) {
// ...
}
const binaryData = decode(base64String)
//create a Uint8Array to represent the binary data
const buffer = new Uint8Array(binaryData.length)
for (let i = 0; i < binaryData.length; i++) {
buffer[i] = binaryData.charCodeAt(i)
}
//create a File object from the binary data
const file = new File([binaryData], 'data', { type: 'image/jpeg' })
formDataBody.append('data', file)
I am also aware that modules like react-native-fs can be utilized, but I encountered an error message:
ERROR Invariant Violation: "main" has not been registered. This can happen if:
Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
A module failed to load due to an error and `AppRegistry.registerComponent` wasn't called., js engine: hermes
Any assistance or guidance on this matter would be greatly appreciated!