I have configured my project to upload an images to Cloudinary (Cloud storage for images). In my cloudinary account i have created a folder of my application name say MyAppImages. Now my requirement is that my uploaded images through MyApp application should go to MyAppImages folder.
With my current code it is going directly to Samples folder.
My Code:
{
String fileName=multipartFile.getOriginalFilename();
File physicalFile=new File(multipartFile.getOriginalFilename());
FileOutputStream fout=new FileOutputStream(fileDir.getName()+"/"+physicalFile);
fout.write(multipartFile.getBytes());
fout.close();
Cloudinary cloudinary = new Cloudinary(ObjectUtils.asMap(
"cloud_name", "my_cloud_name",
"api_key", "my_key",
"api_secret", "my_secret"));
File toUpload = new File("rowFiles/"+fileName);
Map params = ObjectUtils.asMap("public_id", "MyAppImages/"+fileName);
Map uploadResult = cloudinary.uploader().upload(toUpload, params );
System.out.println("==============>>"+uploadResult.get("url"));
cloudinaryImgURL=uploadResult.get("url").toString();
}
with above code i am able to upload image to specific directory MyAppImages , but with exactly name with original image name. I want to store it image by cloudinary generated random name, so that if i upload the same image twice it should not override first image with second uploaded image as is happening with above code.