Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to perform file upload monitoring with Play! framework

Is it possible to monitor file uploads, somehow, with Play! framework? Also, if the file should be BIG (i.e. +500MB), would it be possible to save the received bytes into a temporary file instead of keeping it in memory? (see update below)

note : there is no code to show as I'm wondering these questions and cannot seem to find the answers with Google

Thanks!

** Update **

(I almost forgot about this question.) Well, apparantly, files uploaded are stored in temporary files, and the files are not passed as a byte array (or something), but as a Java File object to the action controller.

But even in a RESTful environment, file monitoring can be achieved.

** Update 2 **

Is there a way to get early event listeners on incoming HTTP requests? This could allow for monitoring request data transfer.

like image 844
Yanick Rochon Avatar asked Jun 10 '11 05:06

Yanick Rochon


People also ask

How do I upload files to spring boot?

Spring Boot file uploader Create a Spring @Controller class; Add a method to the controller class which takes Spring's MultipartFile as an argument; Save the uploaded file to a directory on the server; and. Send a response code to the client indicating the Spring file upload was successful.

What is multipart file upload?

Multipart upload allows you to upload a single object as a set of parts. Each part is a contiguous portion of the object's data. You can upload these object parts independently and in any order. If transmission of any part fails, you can retransmit that part without affecting other parts.

What is the use of multipart file upload in Java?

Uploading files in a form using multipart/form-data The standard way to upload files in a web application is to use a form with a special multipart/form-data encoding, which lets you mix standard form data with file attachment data. Note: The HTTP method used to submit the form must be POST (not GET ).

What is spring boot MultipartFile?

public interface MultipartFile extends InputStreamSource. A representation of an uploaded file received in a multipart request. The file contents are either stored in memory or temporarily on disk. In either case, the user is responsible for copying file contents to a session-level or persistent store as and if desired ...


1 Answers

Large requests and temp files

Play! is already storing large HTTP requests in temp files named after UUIDs (thus reducing the memory footprint of the server). Once the request is done, this file gets deleted.

Monitoring uploads in Play!

Play! is using (the awesome) Netty project for its HTTP server stack (and also on the client stack, if you're considering Async HTTP client.

Netty is:

  • asynchronous
  • event-driven
  • 100% HTTP

Given Play!'s stack, you should be able to implement your "upload progress bar" or something. Actually, Async HTTP client already achieves progress listeners for file uplaods and resumable download (see the quick start guide).

But play.server package doesn't seem to provide such functionality/extension point.

Monitoring uploads anyway

I think Play! is meant to be behind a "real" HTTP server in reverse proxy mode (like nginx or lighthttpd).

So you'd better off using an upload progress module for one of those servers (like HttpUploadProgressModule for nginx) than messing with Play!'s HTTP stack.

like image 198
Brian Clozel Avatar answered Sep 19 '22 16:09

Brian Clozel