File upload via play-2.6 using java

I am trying to upload file (especially .xlsx) and store it in the project folder. I am using play 2.6.3, java and angular. I have created a browse button and written function to call the rest API in the server.
As of now, if the file is uploaded it will be sent it to the server. I have referred this play documentation. The server method will created file in the directory -users/user/AppData/local/temp/multipartBody482250299404201tempFile.

	public Result uploadFile() {
        play.mvc.Http.MultipartFormData body = request().body().asMultipartFormData();
		play.mvc.Http.MultipartFormData.FilePart file = body.getFile("file");
		File f = (File) file.getFile();
		return ok("File uploaded");

I have created file and pasted the code from the documentation (Writing a custom multipart file part body parser).
How to store excel file? How can i convert this tempFile into excel?

Hi @Satheesh,

the uploaded file is placed on a temporal folder that’s periodically deleted so you should use the File descriptor provided to read the bytes (use, for example a FileInputStream or any other tool to read from disk) from the temporal folder and store them in a permanent storage (database, blob storage, shared disk,…). When moving the bytes from the temporal folder to its final location, make sure you also maintain the metadata (content type, file name, size) saved with it.


Thank you @ignasi35, I have fixed the issue by using FileInputStream.