You use an HTML5 field to upload a DnD file, don’t know? I don’t know what functions JS provides, but usually when you drop a file, it automatically downloads it. I suggest you use the YouTube upload function. For instance:
After downloading the file, return json with the generated file identifier, so when saving records, you can link it to the file you downloaded.
When I played with it, as a rule, javascript will open a new POST request, this request should get it from request.body , which is InputStream , use InputStream with IOUtils to save the file after saving return a JSON object with the file name or path file.
Thing is, I don’t think it will ever go through File files[] because javascript opens a new POST request, so it will always return the wrong value since it never populates when you send data to the server.
You can try: create two routes: one that downloads a file that saves the metadata of the file, using one method that you do all the file processing, and the other takes a json response and binds it then save.
I also posted here some code examples for a similar question: PlayFramework: Ajax + Drag n 'Drop + File Download + File Object in the controller?
Greetings, I'm sorry if I feel a little redundant, as if tired, but I hope this helps you :)
source share