Skip to content

TypeError: Failed to fetch - Error is showing while uploading images to aws #6

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

Closed
Afsana1313 opened this issue Aug 20, 2022 · 7 comments

Comments

@Afsana1313
Copy link

Afsana1313 commented Aug 20, 2022

I am getting errors while implementing react-aws-s3-typescript. Here is my code -

function App() {
async function handleImageChange(e: any) {
e.preventDefault();
await getCredentials();
const config = {
bucketName: "bucketName",
dirName: "/dirName/Images",
region: "us-east-1",
accessKeyId: localStorage.getItem("accessKey"),
secretAccessKey: localStorage.getItem("secretKey")
};
const s3 = new ReactS3Client(config as IConfig);
let uploadedFile = e.target.files[0];
return (
<div className="App">
<input
className="select-image-btn"
type="file"
onChange={(e) => handleImageChange(e)}
/>
</div>);}

the Error I am getting is -

POST https://bucketName.s3-us-east-1.amazonaws.com/ net::ERR_NAME_NOT_RESOLVED
and

TypeError: Failed to fetch at ReactS3Client.<anonymous> (react-aws-s3.js:92:1) at step (react-aws-s3.js:44:1) at Object.next (react-aws-s3.js:25:1) at react-aws-s3.js:19:1 at new Promise (<anonymous>) at __webpack_modules__../node_modules/react-aws-s3-typescript/dist/react-aws-s3.js.__awaiter (react-aws-s3.js:15:1) at ReactS3Client.uploadFile (react-aws-s3.js:65:1) at handleImageChange (App.tsx:27:1)

I am unable to understand the reason for the error shown in the console. Can anyone help me in understanding the problem?

@NimperX
Copy link
Owner

NimperX commented Aug 21, 2022

Hi @Afsana1313 ,

Have you created a bucket in your AWS account? if yes, please replace "bucketName" in the config object with your bucket name. Otherwise, create a S3 bucket to store files and then replace the bucket name in the config object

@Afsana1313
Copy link
Author

Afsana1313 commented Aug 21, 2022

Hi @NimperX,
I had an account. For privacy, I hid the bucket name.

@NimperX
Copy link
Owner

NimperX commented Aug 21, 2022

@Afsana1313 If you have set the correct permissions for the bucket, then you will get following screen when go to https://bucketName.s3-us-east-1.amazonaws.com/ in your web browser.
image

@jainesh2906
Copy link

I have provided the bucketName in the config object but still I am getting failed to fetch error while uploading image or video on the s3

@Afsana1313
Copy link
Author

@jainesh2906 , Please double check your actual s3url if it is valid or not, the service you are using provided from aws, if you need to use any encrypted data

@jainesh2906
Copy link

This is the s3Url: 'https://dint.s3.amazonaws.com' I have added

@NimperX
Copy link
Owner

NimperX commented Dec 6, 2022

@jainesh2906 Is this fixed? If yes, please acknowledge.

NimperX added a commit that referenced this issue Dec 6, 2022
@NimperX NimperX closed this as completed Dec 6, 2022
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

3 participants