Fausto95 / aws-s3

S3Client - A Javascript Library for AWS S3 File Upload

Home Page:https://www.npmjs.com/package/aws-s3

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fetch fails error even though files write to S3

wvicioso opened this issue · comments

My issue is very weird. I am using the upload function to write an image into an S3 Bucket. When I execute the upload function, I get an error saying "Fetch Failed" but when I check my S3 Bucket on AWS, the image is there.

So basically, I am getting a "Fetch Failed" error even though it did not fail since my image object gets written to my S3 Bucket.

I am not sure if this is a bug with this library or with my permissions on AWS.

My current fix includes adding a catch error to the upload's fetch request and also hard-coding a status value to the promise. Cleary this is not a real solution since I am basically just ignoring the error.

      await fetch(url, { method: "post", body: fd })
      .catch(error => { console.log('error uploading', error) })
      return Promise.resolve({
        bucket: this.config.bucketName,
        key: `${this.config.dirName ? this.config.dirName + "/" : ""}${fileName}`,
        location: `${url}/${this.config.dirName ? this.config.dirName + "/" : ""}${fileName}`,
        status: 200
      });