任何人都可以帮助我。代码正常用于图片上传但是我想在文件路径中给出字节值。因为图像数据类型是CommonsMultipartFile。
@RequestMapping(value = "/saveImage", method = RequestMethod.POST)
public @ResponseBody ImageResultVO getImage(ImageCriteriaVO imageCriteriaVO) throws O2Exception, IOException
{
CommonsMultipartFile file ;
file =(CommonsMultipartFile) imageCriteriaVO.getImage();
AWSCredentials credentials = new BasicAWSCredentials(System.getenv("AWS_ACCESS_KEY_ID") ,System.getenv("AWS_SECRET_ACCESS_KEY"));
String SUFFIX = "/";
String folderName = "images";
String existingBucketName = "o2container";
String keyName = folderName + SUFFIX + file.getOriginalFilename();
System.out.println("image" +keyName);
String filePath = "D:/bhanu/images%20(4).JPG";
System.out.println("filePath" +filePath);
String amazonFileUploadLocationOriginal=existingBucketName;
System.out.println("hello");
AmazonS3 s3Client = new AmazonS3Client(credentials);
System.out.println("hello1");
FileInputStream stream = new FileInputStream(filePath);
System.out.println("hello2");
ObjectMetadata objectMetadata = new ObjectMetadata();
System.out.println("hello3");
PutObjectRequest putObjectRequest = new PutObjectRequest(amazonFileUploadLocationOriginal, keyName, stream, objectMetadata);
System.out.println("hello4");
PutObjectResult result = s3Client.putObject(putObjectRequest);
System.out.println("Etag:" + result.getETag() + "-->" + result);
return null;
}
答案 0 :(得分:0)
putObject
的版本接受InputStream
而不是文件路径:
putObject(String bucketName, String key, InputStream input, ObjectMetadata metadata)
在指定的存储分区和密钥名称下将指定的输入流和对象元数据上载到Amazon S3。