0

I am trying to upload media files to amazon s3 using amplify, it works on ios but throws an error on android (ERROR RangeError: Failed to construct 'Response': The status provided (0) is outside the range [200, 599]., js engine: hermes). I have not idea what is that cause the problem. This is my function and permissions:

 // get permissions
  useEffect(() => {
    const getPermissionAsync = async () => {
      const { status } = await MediaLibrary.requestPermissionsAsync();
      if (status !== "granted") {
        alert("Sorry, we need media library permission to select an image.");
      }
    };
    getPermissionAsync();
  }, []);

  //upload to amazon s3
  const uploadToS3 = async (uri) => {
    try {
      const fileType = uri.split(".").pop();
      const fileName = `${new Date().getTime()}.${fileType}`;
      console.log("this is the file name", fileName);
      const response = await fetch(uri);
      const blob = await response.blob();
      const result = await Storage.put(fileName, blob, {
        contentType: "image/jpeg",
        ACL: "public-read", // This makes the file public
      });
      const cloudFrontURL = `https://dijtywqe2wqrv.cloudfront.net/public/${result.key}`;
      return cloudFrontURL;
    } catch (error) {
      console.error("Error uploading file:", error);
    }
  };
  • Does this answer your question? [React Native Blob fetch throws error: Failed to construct 'Response': The status provided (0) is outside the range \[200, 599\]](https://stackoverflow.com/questions/76754693/react-native-blob-fetch-throws-error-failed-to-construct-response-the-status) – FutureJJ Sep 02 '23 at 03:14

0 Answers0