我是Spring boot和angular js的新手。在我的控制器(Angular文件上传)中我有 -
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();
}
}
感谢您仔细阅读,如果您有任何线索,请用同样的方式更新我
答案 0 :(得分:0)
最好使用aws-javascript-sdk将内容上传到aws。
它确实通过httpUploadProgress
和httpDownloadProgress