Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{"headers": {}, "status": 0, "text": "Stream Closed"} #109

Open
johnny-washswat opened this issue Jan 13, 2023 · 13 comments
Open

{"headers": {}, "status": 0, "text": "Stream Closed"} #109

johnny-washswat opened this issue Jan 13, 2023 · 13 comments

Comments

@johnny-washswat
Copy link

I am having an issue with android only when I try to upload image

{"headers": {}, "status": 0, "text": "Stream Closed"}

@MarySnopok
Copy link

Facing same error , that is reoccurring on gallery access for Android devices. Would be great to have some feedback on the issue.

@dev-avishek
Copy link

Facing the same issue,
Package version --> "react-native-aws3": "^0.0.9"

System:
OS: Windows 10 10.0.22621
CPU: (8) x64 Intel(R) Core(TM) i5-10210U CPU @ 1.60GHz
Memory: 5.60 GB / 15.83 GB
Binaries:
Node: 16.17.1
Yarn: 1.22.19
npm: 8.15.0
Watchman: 20220918.223204.0
SDKs:
Android SDK:
API Levels: 28, 31, 32, 33
Build Tools: 30.0.2, 30.0.3, 31.0.0, 33.0.0
System Images: android-33 | Google APIs Intel x86 Atom_64, android-33 | Google Play Intel x86 Atom_64
Android NDK: Not Found
Windows SDK: Not Found
IDEs:
Android Studio: AI-221.6008.13.2211.9514443
Visual Studio: Not Found
Languages:
Java: 17.0.6
npmPackages:
@react-native-community/cli: Not Found
react: 18.2.0 => 18.2.0
react-native: 0.71.8 => 0.71.8
react-native-windows: Not Found
npmGlobalPackages:
react-native: Not Found

@asfaqehussain
Copy link

Did you get the solution for this issue ?
I'm facing the same with react native version 71.11

@johnny-washswat
Copy link
Author

johnny-washswat commented Jul 4, 2023

Did you get the solution for this issue ? I'm facing the same with react native version 71.11

I wanted to bring to your attention that this package is no longer being maintained. However, I have created a new package that you can check out for your needs: react-native-aws3-manager

Additionally, I'd like to share a code snippet that might be helpful for those encountering upload issues. This approach retries the handleUploadImage function within a try-catch block:

try { await handleUploadImage(file, result, path); if (index === images.length - 1) { resolve(result); } } catch (e) { await handleUploadImage(file, result, path); if (index === images.length - 1) { resolve(result); } }

@dev-avishek
Copy link

@johnny-washswat @asfaqehussain the issue persists. Looks like there is a CORS or header issue and maybe AWS has introduced some new fine-grained security rules to upload blob into s3. So, maybe that is the reason why the package keeps breaking.

Also, for me, it happens when I'm trying to upload a couple of blob images/docs consecutively. To tackle it I have put the function inside the try{}catch{} block and once it failed showing a confirmation to the user to upload the file/image again. That's the hack for now that I'm using not super convenient though. 🤔

@asfaqehussain
Copy link

Resolved for me.
The issue was with the wifi connection (weird), with mobile hotspot or changing the network it works perfectly.
@johnny-washswat try changing the internet connection.

@dev-avishek
Copy link

Resolved for me. The issue was with the wifi connection (weird), with mobile hotspot or changing the network it works perfectly. @johnny-washswat try changing the internet connection.

Really, sounds weird but great if that solves the issue, I'll try and give you the update.

@dev-avishek
Copy link

@asfaqehussain this is still there if I switched my internet. Did you test on Debug APK or Prod?

@asfaqehussain
Copy link

@asfaqehussain this is still there if I switched my internet. Did you test on Debug APK or Prod?

In debug

@MuhammadFaisal12q
Copy link

i am also facing same issue any updates ?

@asfaqehussain
Copy link

@MuhammadFaisal12q I got it resolved by changing the ACL permissions.

@MuhammadFaisal12q
Copy link

johnny-washswa
Issue Fixed
i tried @johnny-washswat solution
What i did was i put inside the try catch when the error occurs i call the same function which i used inside try so, when the it catches error it call the uploadImage function again ........................

@MuhammadFaisal12q
Copy link

MuhammadFaisal12q commented Feb 20, 2024

This Works for me !!
I use For loop ... if file upload fails it try at max attempts ...after max attempts if still file upload fails it show user error message
"Failed to upload file ...."

async function uploadFile(filePath, fileName, fileType, s3key, maxRetries = 3) {
   
  const file = {
    uri: filePath,
    name: fileName,
    type: fileType
  }

  const options = {
    keyPrefix: "",
    bucket: s3key?.bucket,
    region: s3key?.region,
    accessKey: s3key?.accessKey,
    secretKey: s3key?.secretKey,
    successActionStatus: 201
  }

  let res = { status: 0, response: null };
  // Check if all necessary properties are set
  if (!options.bucket || !options.region || !options.accessKey || !options.secretKey) {
    console.log('One or more S3 configuration options are missing.');
    return;
  }

  let uploadSuccessful = false;

  for (let i = 0; i < maxRetries; i++) {
    try {
      const response = await RNS3.put(file, options);
      if (response?.status == 201) {
        res = { status: 201, response: response?.body?.postResponse?.location };
        uploadSuccessful = true;
        break;
      } else {
        res = { status: response?.status, response: response?.text?.match(/<Code>(.*?)<\/Code>/)?.[1] }
      }
    } catch (exception) {
      console.log(`S3 exception = ${JSON.stringify(exception)}`);
      if (i === maxRetries - 1) {
        uploadSuccessful = false;
      }
    }
  }

  if (!uploadSuccessful) {
    ALERT.ShowAlert_Snackbar("Failed to upload file...", STYLE_STRING.COLOR.ERROR);
  }

  return res;
}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants