Thanks for the reply hcarvalhoalves. I can see bypassing the file name extensions as you have mentioned, they don't guarantee the file type anyway. That said, I would like to be able to use some other means than mimetypes as I need to make sure that the files are of a specific type (e.g. not just a video file but one with a specific file header.)
As for the interruption of the upload itself however, that is pretty crucial as the files would be around 1 GB each and I wouldn't want a user to have to wait for it to complete only to find out that it was of the wrong file type. On Mar 13, 9:39 pm, hcarvalhoalves <hcarvalhoal...@gmail.com> wrote: > You could avoid the Javascript check (file extensions are just a > convention, rarely thrustable) and just check the uploaded file > mimetype on form validation code. > > `import mimetypes` for more. > > There's no clean way to interrupt file upload, though. > > On Mar 12, 11:27 pm, Vincent <jellygr...@gmail.com> wrote: > > > I would like some help in figuring out how to handle file validation > > in my application. I have a series of processing that I'd like to > > happen at various stages. Some of this validation might have to happen > > outside of Django itself, like using JavaScript in the actual form as > > the files that are to be uploaded can be quite large in size. > > > For starters, I would like the extension of the selected file to be > > checked prior to submission. I have no experience with JavaScript but > > I take it that I can perform some sort of regex search there? I take > > it that this has been done before. Could some one point me in the > > direction of a clear and somewhat simple method of doing this with > > either a simple self-made script or one built-in to a library? > > > If the filename passes validation, I want the form to be submitted BUT > > it would be great if there was some way to check the first few bytes > > of the file as it is being uploaded on the server-side. I should know > > that the first few bytes of a correct file look like and can do a > > regex search against a known list of strings. How does one check a > > file while it's being uploaded in Django? Also, how does one trigger > > and error or warning so that the upload stops and displays an error > > page to the user? > > > I'm still pretty new to a lot of what Django provides as well as > > Python in general so please pardon me if this are well-documented and/ > > or know procedures. > > > Thanks -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.