1

我是 Spring Boot 和 Angular js 的新手。在我的控制器中(角度文件上传)我有 -

app.controller('AppController_img', ['$scope', 'FileUploader','Restangular','ngDialog', function($scope, FileUploader,Restangular,ngDialog) {
    var uploader = $scope.uploader = new FileUploader({
        url: 'https://angular-file-upload-cors-srv.appspot.com/uploadI'
    });

在我的角度文件上传控制器的进度事件中,我有 -

uploader.onProgressItem = function(fileItem, progress) {
      /*  console.info('onProgressItem', fileItem, progress);*/
        console.log(progress);
        $scope.abcd=true;
    };

在服务器端——

我使用了 MultiPartFile。我正在尝试使用 putObjectRequest 方法将图像上传到 Amazon Server 存储桶 (s3)。我将文件上传到存储桶,但在前端,上传程序的进度条立即运行到 99%,然后停止。我试图用谷歌搜索它,但找不到任何解决方案。

以下是参考代码-

@RequestMapping(value="/uploadI", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
 @ResponseBody
 public Success uploadImage( @RequestParam("file") MultipartFile file, HttpServletResponse response,final HttpServletRequest request)
         throws ServletException, IllegalStateException, IOException {

AmazonS3 s3client = new AmazonS3Client(credentials);   
String name = file.getOriginalFilename();
        InputStream is = file.getInputStream();
        String fileName = folderName + SUFFIX + name; 
String bucketName = "abc.in";
        String folderName = "xyz";          

         if (!file.isEmpty()) {
                try {

                    byte[] contentBytes = IOUtils.toByteArray(is);
                    Long contentLength = Long.valueOf(contentBytes.length);
                    ObjectMetadata metadata = new ObjectMetadata();
                    metadata.setContentLength(contentLength);
                    System.out.println(contentLength);
                    metadata.setContentType(file.getContentType());
                    PutObjectRequest putObjectRequest = new PutObjectRequest(
                            bucketName, fileName, file.getInputStream(), metadata)
                            .withStorageClass(StorageClass.ReducedRedundancy);


                    s3client.putObject(putObjectRequest);
}catch (Exception e) {
                    e.getStackTrace();
}
}

感谢您完成此操作,如果您有任何线索,请以相同的方式更新我

4

1 回答 1

0

最好使用 aws-javascript-sdk 将内容上传到 aws。

它确实通过像httpUploadProgresshttpDownloadProgress

于 2015-09-16T11:07:33.997 回答