“Error processing request body” occurs randomly when sending image to server

  1. SDK Version: 34, 35, 36 and 37
  2. Platforms(Android/iOS/web/all): iOS

I have recently been having a problem with the iOS version of the app I am developing. Often when sending an image to the server (selected utilizing the component expo-image-picker), it returns the error:

Error procession request body: Error Domain=ABI34_0_0RCTErrorDomain Code=0
"Invalid request token"
UserInfo={NSLocalizedDescription=Invalid request token.}

This is the method sending the data:

alterUserDataOnDatabase(formValues, callback) {
        fetch(url , {
            method: 'POST',
            headers: {
                Accept: 'application/json',
                'Content-Type': 'multipart/form-data',
            },
            body: formValues
        })
          .then(response => response.json())
          .then(responseJson => callback(responseJson));
}

And this is the code to get the image itself using image picker

_pickImage = async () => {
        const {
            status: cameraRollPerm
        } = await ImagePicker.getCameraRollPermissionsAsync();
        //await Permissions.getAsync(Permissions.CAMERA_ROLL);

        // only if user allows permission to camera roll
        if (cameraRollPerm === 'granted') {
            try {
                let pickerResult = await ImagePicker.launchImageLibraryAsync({
                    allowsEditing: true,
                    aspect: [4, 4],
                });

                this._handleImagePicked(pickerResult);
            } catch (e) {
                console.log(e)
            }
        }
};

_handleImagePicked = async pickerResult => {
        try {
            this.setState({
                uploading: true
            });

            if (!pickerResult.cancelled) {
                let uri = pickerResult.uri;
                let uriParts = uri.split('.');
                let fileType = uriParts[uriParts.length - 1];

                this.form.append('photo', {
                    uri: uri,
                    name: `photo.${fileType}`,
                    type: `image/${fileType}`,
                });

                this.setState({
                    image: uri
                });
            }
        } catch (e) {
            console.log({ e });
            alert('Upload failed, sorry :(');
        } finally {
            this.setState({
                uploading: false
            });
        }
};

I was using expo and react-native in its 34 version, I have tried them to the version 36, but it didn’t do anything for it, the error merely changed from ABI34 to ABI36.

The error occurs only sometimes, which is the odd part, it seems to happen at random, but the usually, after sending one image, the next one will return the error, though sometimes it happens the first time I try to send. I have tried creating another app, and this other app actually works with the same code.

Does anyone know anything about this error, I am having a hard time finding answers to it.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.