开发者

How to perform file upload monitoring with Play! framework

开发者 https://www.devze.com 2023-03-12 02:02 出处:网络
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 k

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消