Skip to content

Can't upload file. Got TypeError: Network request failed #12

@danielcdcj

Description

@danielcdcj

Below is my test code for uploading raw text file.
Whenever I run S3.uploadFile(), I get [TypeError: Network request failed]
The S3.listFile() method is working for me

import ReactS3Client from 'react-aws-s3-typescript';

export default class S3 {
    static s3Config = {
        bucketName:  'xxx',
        region: 'us-east-1',
        accessKeyId:'xxx',
        secretAccessKey: 'xxx',
    }

    static async uploadFile() {
        let file = new File(["test"], "testFile.text", { type: 'text/plain' });    // test file
        const s3 = new ReactS3Client(S3.s3Config);
        try {
            const res = await s3.uploadFile(file, "testFile.text");
            console.log(res);
        } catch (exception) {
            console.log(exception);
        }
    }

    static async listFile() {
        const s3 = new ReactS3Client(S3.s3Config);
        s3.listFiles().then((res) => {
            console.log(res.data.Contents);
        })
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions