'why get 413 error when upload image with 'expo ImagePicker camera'?

If I take a photo with the camera, I get this error: Error: Request failed with status code 413.

But if I select and upload a photo from the phone gallery, there will be no problem. The size of the photo I upload was below 5mb both with the camera and with the gallery.

const formData = new FormData();

    let localUri = image.value.uri;
    let filename = localUri.split('/').pop();
    let type = mime.getType(localUri);

    image.blob &&
      formData.append('photo', { uri: localUri, name: filename, type });


const pickImageFromGallery = async () => {
    let result = await ImagePicker.launchImageLibraryAsync({
      mediaTypes: ImagePicker.MediaTypeOptions.Images,
      allowsEditing: true,
      aspect: [16, 9],
      base64: true,
    });

    if (!result.cancelled) {
      const response = await fetch(result.uri);
      const blob = await response.blob();
      if (blob.size && blob.size / 1024 < 5120) {
        setImage({
          value: result,
          blob: blob,
          error: false,
        });
      } else {
        alert('File size is too large. Please upload files below 5MB!');
      }
    }
  };

const pickImageFromCamera = async () => {
    let result = await ImagePicker.launchCameraAsync({
      mediaTypes: ImagePicker.MediaTypeOptions.Images,
      allowsEditing: true,
      aspect: [16, 9],
      base64: true,
    });

    if (!result.cancelled) {
      const response = await fetch(result.uri);
      const blob = await response.blob();

      if (blob.size && blob.size / 1024 < 5120) {
        setImage({
          value: result,
          blob: blob,
          error: false,
        });
      } else {
        alert('File size is too large. Please upload files below 5MB!');
      }
    }
  };


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source