Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 为什么我的图像不能正确上传到AWS S3?_Reactjs_Amazon S3 - Fatal编程技术网

Reactjs 为什么我的图像不能正确上传到AWS S3?

Reactjs 为什么我的图像不能正确上传到AWS S3?,reactjs,amazon-s3,Reactjs,Amazon S3,我正在尝试将图像上载到AWS S3,但它不起作用。 出现一个文件,但它太小,无法作为图像,并且无法在S3中正确打开 我不确定我的哪些参数是错误的。 我试图上传的文件名为picture.jpg 以下是我当前的代码: import React , {Component} from 'react'; import logo from './logo.svg'; import './App.css'; import AWS from 'aws-sdk'; AWS.config.update({

我正在尝试将图像上载到AWS S3,但它不起作用。 出现一个文件,但它太小,无法作为图像,并且无法在S3中正确打开

我不确定我的哪些参数是错误的。 我试图上传的文件名为picture.jpg

以下是我当前的代码:

import React , {Component} from 'react';
import logo from './logo.svg';
import './App.css';
import AWS from 'aws-sdk';

AWS.config.update({
    accessKeyId: "xxxxxx",
    secretAccessKey: "xxxxxx",
});

const s3 = new AWS.S3();


const u = ''
const config = {
    bucketName: 'mybucket', // name of the bucket
    region: 'us-east-1',
    accessKeyId: 'xxxxxx',
    secretAccessKey: 'xxxxxxx',
}

class App extends Component {
  constructor() {
    super();
    this.state ={
      url: u,
    }
    this.upload = this.upload.bind(this);
  }

  upload(e) {
    var params = { 
      Body: e.target.files[0],
      Bucket: "mybucket", 
      Key: "picture.jpg", // call the new image Thisnewpic.jpg
    };
    s3.putObject(params, function(err, data) {
     if (err) console.log(err, err.stack); // an error occurred
     else     console.log(data);           // successful response
      });

  }

  render() {
    return ( <div>
      Upload AWS S3
      <input 
        type="file"
        onChange={this.upload}
      />
      <button onClick={this.delete}>Delete</button>
      <img src={this.state.url} />
    </div>);
  }
}

export default App;

谢谢。

首先,您是否尝试过通过控制台或CLI上传它?首先,您是否尝试过通过控制台或CLI上传它?