Django application that can provide user-friendly, multiple / bulk file uploads to other applications

I will be honest: this is the question I asked in the Django-Users mail list last week. Since I have not received any answers yet, I am rewriting it on Qaru in the hope that it will get more attention here.

I want to create an application that simplifies usability, multi-user file upload to my own applications. With a user-friendly, I have an average download like Gmail, Flickr, ... where the user can select several files at once in the browse file dialog box. Then the files are downloaded sequentially or in parallel and a good overview of the selected files is displayed on the page with a progress bar next to them. The "Cancel" download button is also an option.

All this attractiveness is usually solved with the help of a Flash object. full solutions for the client side, for example: SWFUpload http://swfupload.org/ , FancyUpload http://digitarald.de/project/fancyupload/ , YUI 2 Uploader http://developer.yahoo.com/yui/uploader/ and perhaps many more.

Of course, the trick is that these solutions are integrated into your project. Especially within Django, if you want it should be reused.

So, I have a few ideas, but I'm not an expert on Django and not Flash-based download solutions. I will share my ideas here, hoping to get some feedback from more knowledgeable and experienced people. (Or even some β€œI want this too!”) :)

You will notice that I make several assumptions: this is to keep the (initial) volume of the application under control. These assumptions are of course debatable:

Ok, my idea so far:

  • If you want to bulk upload multiple files, you will have a model to place each file. Ie model will contain one FileField or one ImageField. Models with multiple (but finite) number of FileFields / ImageFields files do not need simple bulk upload imho: if you have a model with 100 FileFields you are doing something wrong :) Examples in which you would like my intended bulk upload :

    • An application that has only one Brochure model with a file field, a header field (dynamically created from the file name), and a date_added field.
    • Application for photo gallery with gallery 'Gallery' and 'Photo'. You select Gallery to add photos, upload photos and new photo objects and foreign keys are installed in the selected gallery.
  • It would be nice to customize or extend the application for your favorite Flash download solution. We can choose one of three by default, but implement the application so that people can easily add additional implementations (like Django can use several databases). Let it be agnostic for any specific client solution.

  • If we need to choose it for a start, perhaps choose the one that has the smallest footprint? (smallest client load)

  • Asynchronously (and sequentially or in parallel) POST files on the URL. I suggest that the URL be local to our universal application (the way it is for every application in which you use our application in). This URL will go to the view provided by our shared application.

  • The view will do the following: create an instance of a new model, add a file, ADDITIONALLY ADD A PAGE, and save the instance.

  • DO EXTRA STUFF is the code that the application that uses our application wants to run. It should not provide any additional code if the model has only FileField / ImageField will execute standard view code. But most applications will want to do additional things, which, it seems to me, are other fields: title, date_added, foreignkeys, manytomany, ...

  • I have not thought about the DO EXTRA STUFF mechanism yet. The general idea of ​​the application just turned around, but this is not a developer, since you have to write your own URL pattern and your own look. Then you should tell Flash solutions to use the new URL, etc ... I think you can use something like signals here?

  • Forms / Admin: I'm still very sketchy how all this can be better integrated into Admin or Django general forms / widgets / ... (and this was my lack of Django experience):

    • In the case of the Gallery / Photo application: you can provide a mass photo upload widget in the details of the gallery form. But what if the gallery instance has not yet been saved? A boot preview file will not be able to set additional objects in the photo instances. I see that the auth application, when you create a user, first asks for a username and password and only then provides you with forms for filling in email, choosing roles, etc. We could do something like that.
    • In the case of a single model application: How do you provide the form in the Django admin to create your mass upload? You cannot do this using the detailed form of your model, this is for only one instance of the model.

There are probably a few more questions that need to be answered before. I can even start with this application. So please tell me what you think! Give me an input! What do you like? What's wrong? What would you do differently? Is this idea solid? Where is it not?

Thanks!

+7
django upload
source share
1 answer

I just released a simple app for this about a month ago: django-uploadify .

This is basically a Django template tag that acts as a wrapper for the very sleek Uploadify (jQuery required). Using it is as simple as adding this to your template ...

{% load uploadify_tags }{% multi_file_upload '/upload/complete/url/' %} 

The tag will fire events (1 per file) both on the client side and on the server side (Django signal) to indicate when the incoming file was received.

For example, if you have a Media model that processes all files uploaded by a user ...

 def upload_received_handler(sender, data, **kwargs): if file: new_media = Media.objects.create( file = data, new_upload = True, ) new_media.save() upload_recieved.connect(upload_received_handler, dispatch_uid='whatever.upload_received') 

Check out the wiki for information on how to configure it and create signal handlers (client / server).


About your conceptual implementation from above, here are a few considerations:

  • Having an application automatically creates an instance of the β€œFile Model,” probably not as durable as people may already have their own models with which they work with
  • If you want to implement any type of security or authentication, you need an open system and less of the type of "auto-create"
  • I really think signals / events are a way to handle this, and also handle the β€œDO OTHER STUFF” part of what you mentioned.
  • My conclusion was that multi-loading can never be a form widget in the sense that Django implements form widgets. 1 file will most likely be represented by an instance of 1 model (with some exceptions), which means that we will end the situation when 1 widget can represent instances of N models. However, Django is configured so that the widget represents 1 value for 1 field in 1 instance. It just is not suitable for most use cases to have it in the form of a widget (hence why I went for the tag template).
+12
source share

All Articles