I'm new to Spring-Boot,i'm trying to upload file to Mongodb Database, save its objectId and link it to my document, in order to download it Later. Here is my class Person:
@Document
public class Person {
@Id
private String id;
private String firstName;
private String lastName;
private String age;
private String filename;
private ObjectId file;
....}
This is my controller method:
@RequestMapping(value="/addperson",method=RequestMethod.POST)
public String ajout(Model model,@Valid PersonForm pf){
Person p=new Person(pf.getFirstname(),pf.getLastName(),pf.getAge());
InputStream inputStream=null;
try {
inputStream = new FileInputStream("E:/usb/");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
p.setFilename(pf.getFilename());
repository.linkFileToMyDoc(p,inputStream,p.getFilename());
repository.save(p);
model.addAttribute("PersonForm",pf);
return "personview";
}
I wonder if it is the best method to do it. the error i get is that access to "E:/usb/" is denied. Can anyone help please