如何为AWS S3 Spring,图像上传时间太长

时间:2015-11-11 17:55:37

标签: java spring maven amazon-web-services amazon-s3

16MB图片需要20秒才能上传... 上传20张图片需要3分钟。

我不知道确切的原因。 我写的代码。

Spring 4.1.7 + JAVA8 + Tomcat7.0.64

    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk-s3</artifactId>
        <version>1.10.32</version>
    </dependency>

AWS S3 init

AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
            ClientConfiguration clientConfig = new ClientConfiguration();
            clientConfig.setProtocol(Protocol.HTTP);
            this.amazonS3Client = new AmazonS3Client(credentials, clientConfig);
    //      this.amazonS3Client.setEndpoint("ap-northeast-1.amazonaws.com");
            this.amazonS3Client.setRegion(Region.getRegion(Regions.fromName(region)));

AWS S3上传代码

    private PutObjectResult upload(InputStream inputStream, String uploadKey, ObjectMetadata metadata) {
            PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, uploadKey, inputStream, metadata);
            putObjectRequest.setCannedAcl(CannedAccessControlList.PublicRead);
            PutObjectResult putObjectResult = amazonS3Client.putObject(putObjectRequest);
            IOUtils.closeQuietly(inputStream);
            return putObjectResult;
        }

延迟代码

PutObjectResult putObjectResult = amazonS3Client.putObject(putObjectRequest);

参数

putObjectResults.resultData.add(upload(multipartFile.getInputStream(), tempName, metadata));

数据接收部分

    @RequestMapping(value="/upload" , method = RequestMethod.POST)
    @ResponseBody
    public Object actionProfileUpdate(HttpServletRequest request){
        multipartRequest =  (MultipartHttpServletRequest)request;

        files = new ArrayList<MultipartFile>();
        files.add(multipartRequest.getFiles("ImageFile").get(0));

        MultipartFile[] multipartFiles = files.toArray(new MultipartFile[files.size()]);
        ResultUploadS3VO resultUUploadData = s3.upload(multipartFiles);

我不知道为什么。请帮帮我.. T.T

0 个答案:

没有答案