I am saving files on my S3 Bucket, but I noticed that to do this I use a FileOutPutStream
like so :
private UploadedFile file; // This is from PrimeFaces, the file that the client wishes to upload
File uploadedFile = new File(file.getFileName()); // Leaving the file like this creates the file on my IDE folder AFTER executing the next two lines, thats why I though the next lines were an error.
FileOutputStream fileOutput = new FileOutputStream(uploadedFile);
fileOutput.write(file.getContents());
So this lines of code are responsible of writing the file on my device, I first though that was an error or that wasn't necessary because I don't know much about file uploading to amazon, so I remove this two lines because I notice my method for uploading just needed the file and the filename like so:
businessDelegatorView.uploadPublicRead("mybucketname", fileName, fileToUpload);
So I though this wasn't necessary and that was only duplicating the files:
FileOutputStream fileOutput = new FileOutputStream(uploadedFile);
fileOutput.write(file.getContents());
But I notice that the upload doesn't work if I remove them because it throws a FileNotFoundException
so I started my search and find out this post from BalusC and I get it I have to define a path where the files from my clients will be saved for later upload like in this case to amazon s3 bucket, but I was wondering if, for example doing it like this will work when the .WAR is generated:
File uplodadFile = new File("C:/xampp/apache/conf", file.getFileName());
FileOutputStream fileOutput = new FileOutputStream(uploadFile);
fileOutput.write(file.getContents());
I am saving the files there as a test, but I don't know or not sure if FileOutPutStream
is the right choice, I don't know another way.
Also this is what the method for uploading looks like after the above code has executed, without the FileOutPutStream
it won't work cause file not in my device
AmazonS3 amazonS3 = buildAmazonS3();
try {
amazonS3.putObject(new PutObjectRequest(bucketName, key, file).withCannedAcl(CannedAccessControlList.PublicRead));
Just want somebody to clear things a little bit more for me, like what is the best path to put on here?
File uplodadFile = new File("C:/xampp/apache/conf", file.getFileName());
or it really doesn't matter I just gotta keep in mind in which machine the .WAR will be deployed? thanks