在AWS的S3中上传文件

时间:2017-10-24 22:47:44

标签: java amazon-s3

我在s3中上传文件,编写以下代码:

String filePath=KeyProvider.localFolerPath + KeyProvider.suffix +KeyProvider.FileNameToUpload; 

// upload file to folder and set it to public
String fileName = folderName + KeyProvider.suffix +KeyProvider.remoteFileName ;
s3client.putObject(
            new PutObjectRequest(bucketName, fileName, new File(filePath))
                    .withCannedAcl(CannedAccessControlList.PublicReadWrite));`

那样抛出错误
  

com.amazonaws.services.s3.model.AmazonS3Exception:拒绝访问

请建议我在单独的常量文件中提供了存储桶名称密钥和密码的错误在哪里。

谢谢..

1 个答案:

答案 0 :(得分:3)

你检查过亚马逊的文件吗?

而且,要小心。您需要设置access_key& access_secret字符串到s3客户端。

例如

import React, { Component } from 'react';
import { Router, Route, IndexRoute, hashHistory } from "react-router";

class DetailsComponent extends Component {
  render() {
    return (
      <Router history={hashHistory}>
       // in here will map this.props.data and for each one print a route
       // the component for that route will be a DetailedViewComponent that
       // that takes in the data in the props and renders it
       // so i might need a link? in this render method aswell?
      </Router>
    );
  }
}

export default DetailsComponent ;

修改

S3策略可以根据凭据或IP地址处理拒绝/允许访问。你配置这样的政策吗?