Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

266
Views
How to use the AWS S3 bucket in ant design upload with React js

import React from 'react';
import S3 from 'react-aws-s3';

import {
  Form,
  Upload,
} from 'antd';

const normFile = (e) => {
  console.log('Upload event:', e);

  if (Array.isArray(e)) {
    return e;
  }
  return e && e.fileList;
};

    const props = {
  onStart(file) {
    console.log('onStart', file, file.name);
  },
  onSuccess(res, file) {
    console.log('onSuccess', res, file.name,file);
  },
  onError(err) {
    console.log('onError', err);
  },
  onProgress({ percent }, file) {
    console.log('onProgress', `${percent}%`, file.name);
  },
  async customRequest({
    action,
    data,
    file,
    filename,
    headers,
    onError,
    onProgress,
    onSuccess,
    withCredentials,
  }) {
    const formData = new FormData();
    if (data) {
      Object.keys(data).forEach(key => {
        formData.append(key, data[key]);
      });
    }
    formData.append(filename, file);
    const configSettings = {
      bucketName: 'xxx',
      region: 'ap-south-1',
      accessKeyId: 'xxxxxxxxxx',
      secretAccessKey: 'xxxxxxxxxxxx',
    };
    var S3Client = new S3(configSettings);
    console.log('df', S3Client);
    await S3Client.uploadFile(file.originFileObj, filename)
      .then((data) => {
        console.log('data', data);
        onSuccess(data, fileName);
      })
      .catch(onError);

    return {
      abort() {
        console.log('upload progress is aborted.');
      },
    };
  },
};

const FileUpload = () => {
  return (
    <>
      <Form.Item
        name="dragger"
        valuePropName="fileList"
        getValueFromEvent={normFile}
        noStyle
        {...props}
      >
        <Upload.Dragger name="files" action="/upload.do" {...props}>
          <p className="ant-upload-drag-icon"></p>
          <p className="ant-upload-text">
            Click or drag file to this area to upload
          </p>
          <p className="ant-upload-hint">
            Support for a single or bulk upload.
          </p>
        </Upload.Dragger>
      </Form.Item>
    </>
  );
};

export default FileUpload;

I have used the ant-design upload and react-aws-s3 library here. I have tried the customrequest props way that is not working for me.

I have tried this but isn't working, is there is way?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!