aws / aws-sdk-js-v3

Modularized AWS SDK for JavaScript.
Apache License 2.0
3.06k stars 573 forks source link

Upload blob file in react native ReadableStream doesn't exit #5615

Closed jkpandianbsetec closed 1 month ago

jkpandianbsetec commented 9 months ago

Checkboxes for prior research

Describe the bug

LOG uploadS3>>>> {"ACL": "public-read", "Body": {"blob": {"_data": [Object]}, "name": 1703332949781, "type": "image/jpeg", "uri": "file:///storage/emulated/0/Android/data/com.upliftapps/files/Pictures/e914b6a7-7802-400a-9eff-24e14b4a150b.jpg"}, "Bucket": "bucket", "ContentType": "image/jpeg", "Key": "photos/1703332949781"}

I have picked file and converted file as blob and passed to body params but getting LOG [ReferenceError: Property 'ReadableStream' doesn't exist] ==error from uploads3 this error image image image

SDK version number

@aws-sdk/lib-storage

Which JavaScript Runtime is this issue in?

React Native

Details of the browser/Node.js/ReactNative version

react 18

Reproduction Steps

Observed Behavior

Seems the aws sdk v2 s3.upload working fine but aws sdk v3 not working

Expected Behavior

Seems the aws sdk v2 s3.upload working fine but aws sdk v3 not working. It should work like the v2 behaviour with progress bar

Possible Solution

No response

Additional Information/Context

No response

RanVaknin commented 9 months ago

Hi @jkpandianbsetec ,

I'm not a react native user, but Im a bit confused by two things:

  1. not sure why you are using fetch to read from a local file, after a bit of researching online I found that you can use https://docs.expo.dev/versions/latest/sdk/filesystem/ if you are using Expo. so something like:
    const fileContent = await FileSystem.readAsStringAsync(inputFile.path, { encoding: FileSystem.EncodingType.Base64 });
    const buffer = Buffer.from(fileContent, 'base64');
  1. Im not sure why you are constructing a fileObj? You can just pass in the buffer directly:
    new PutObjectCommand({
      Bucket: bucketName,
      Key: key,
      Body: buffer,
     // rest of params.
    });

Can you give this a try?

Thanks, Ran~

Joshandrews43 commented 9 months ago

Commenting because I have this issue as well, only in production. I use expo-dev-client in my react native app and even with a polyfill, this is not working on a physical device

marcus-menezes commented 5 months ago

I'm having this problem too, got this error: ReferenceError: Property 'ReadableStream' doesn't exist when i send a request to Cognito but has a error in the response. Response 200 working normally.

image I´m using this libs for aws provider config.

I´m try to install web-streams-polyfill but don´t work.

Does anyone have any ideas?

NorseGaud commented 5 months ago

@marcus-menezes , you ever figure this out?

abcarlisle commented 5 months ago

Having this issue as well.

NorseGaud commented 5 months ago

@abcarlisle here is the fix https://stackoverflow.com/a/77744609/1875932

abcarlisle commented 4 months ago

@abcarlisle here is the fix https://stackoverflow.com/a/77744609/1875932

Thank you, however that didn't work for me.

I imported what the stackoverflow response said to at the root of my project with no luck.

I am using expo with these packages. "react-native-get-random-values": "~1.9.0", "react-native-url-polyfill": "^2.0.0", "web-streams-polyfill": "^4.0.0" "@aws-sdk/client-s3": "^3.569.0", "@aws-sdk/lib-storage": "^3.569.0",

NorseGaud commented 4 months ago

@abcarlisle and how are you importing them in your code?

abcarlisle commented 4 months ago

@abcarlisle and how are you importing them in your code?

My apologies that did fix it, I had another unrelated issue. I appreciate the help!

RanVaknin commented 1 month ago

Solution is mentioned here. Closing. Thanks, Ran~

github-actions[bot] commented 1 month ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.