Re: [Cppcms-users] Check space left on device before file upload
Brought to you by:
artyom-beilis
From: Julian P. <ju...@wh...> - 2012-07-11 08:27:07
|
Am 11.07.2012 09:41, schrieb Lee Elenbaas: > > > On Wed, Jul 11, 2012 at 8:09 AM, <ele...@ex... > <mailto:ele...@ex...>> wrote: > > > 1) Check available disk space after client sent Content-Length > header, > > decide whether to accept the request or not > > I suppose, the header could be forged, just like content-type. > > Even if it was not forged - the multi threaded nature of web apps (and > OS for that matter) means that an available space now might not be > there while the file uploads. Yes, even if in our special case one could be quite sure that space is available even during upload, but I agree that this cannot be generalized. Another possibility would be to just close connection as soon as writing to disk fails, causing a Connection Reset in browser. This would be suboptimal though in my opinion, as the user wouldn't know why upload failed. So here it's best to stay with the current behaviour of silently accepting all data from client. > > > > 2) Notify the application code, that upload failed because of > too less > > disk space (maybe one could do this via the existing > infrastructure of > > invoking validate() on the upload form field's widget instance and > > adding another method that would return any occurred errors) > > Please have a look at boost::filesystem::space_info as it should > do the > trick. > > boost::filesystem::space_info will not tell you if the upload failed - > the solution has to come from inside cppcms. The library needs to give > some status for the file upload widget that will say whether the file > was uploaded all right or not. > The set() member function should give you this indication but it does > not set to false if the upload fails to load completely > > I think validate() should also fail, as a file upload which failed to store parts of the file shouldn't be valid under any circumstances. And it would be useful to have some kind of feedback from libcppcms WHY upload failed, so there'd need to be another member method of file widgets that can return an error code or message. Best regards, Julian |