title: Django and Dropzone.js
body: <p>When I upload files with dropzone it adds them to the database, but they don't have a file, just an ID and creation date.  I think the view is the problem but I've tried tons of stuff and I can't figure it out. See my edit below for a more detailed account.</p>
  
  <p>Here is the view</p>
  
  <pre><code>@login_required(login_url='/dashboard-login/')
  def dashboard(request):
      current_user = request.user
      current_client = request.user.client
  
      files = ClientUpload.objects.filter(client=current_client)
  
      form = UploadFileForm()
  
      if request.method == 'POST':
          if request.FILES is None:
              logger = logging.getLogger(__name__)
              logger.warning("No files were attached to the upload.")
              return HttpResponseBadRequest('No Files Attached.')
  
          if form.is_valid():
              upload = form.save()
              form = UploadFileForm(request.POST, request.FILES)
  
          else:
              uploaded_files = [request.FILES.get('file_upload[%d]' % i)
                  for i in range(0, len(request.FILES))]
  
              for f in uploaded_files:
                  client_upload = ClientUpload.objects.create(client=current_client, file_upload=f)
  
              #for key in request.FILES:
              #    cupload = ClientUpload.objects.create(client=current_client, file_upload=request.FILES[key])
  
          logger = logging.getLogger(__name__)
          logger.debug(request.FILES)
          logger.info("File(s) uploaded from " + current_client.company)          
  
          return HttpResponseRedirect(reverse('dashboard'))
  
      data = {'form': form, 'client': current_client, 'files': files}
      return render_to_response('dashboard.html', data, context_instance=RequestContext(request))
  </code></pre>
  
  <p>Here are my dz options:</p>
  
  <pre><code>url: '127.0.0.1:8003/dashboard/',
        method: "post",
        withCredentials: false,
        parallelUploads: 12,
        uploadMultiple: true,
        maxFilesize: 256*4*2,
        paramName: "file_upload",
        createImageThumbnails: true,
        maxThumbnailFilesize: 20,
        thumbnailWidth: 100,
        thumbnailHeight: 100,
        maxFiles: 12,
        params: {},
        clickable: true,
        ignoreHiddenFiles: true,
        acceptedFiles: null,
        acceptedMimeTypes: null,
        autoProcessQueue: false,
        addRemoveLinks: true,
        previewsContainer: null,
        dictDefaultMessage: "Drop files here to upload",
        dictFallbackMessage: "Your browser does not support drag and drop file uploads.",
        dictFallbackText: "Please use the fallback form below to upload your files.",
        dictFileTooBig: "File is too big ({{filesize}}MB). Max filesize: {{maxFilesize}}MB.",
        dictInvalidFileType: "You can't upload files of this type.",
        dictResponseError: "Server responded with {{statusCode}} code.",
        dictCancelUpload: "Cancel upload",
        dictCancelUploadConfirmation: "Are you sure you want to cancel this upload?",
        dictRemoveFile: "Remove",
        dictRemoveFileConfirmation: null,
        dictMaxFilesExceeded: "You can only upload {{maxFiles}} files.",
  </code></pre>
  
  <p>And here is the template:</p>
  
  <pre><code>{% load i18n %}
  {% load staticfiles %}
  {% load crispy_forms_tags %}
  
  &lt;link href="{% static 'css/dropzone2.css' %}" type="text/css" rel="stylesheet"/&gt;
  
  &lt;form class="dropzone" id="myDropzone" method="post" action="{% url 'dashboard' %}" enctype="multipart/form-data"&gt;
      {% csrf_token %}
      &lt;div class="fallback"&gt;
          &lt;input name="file" type="file" multiple /&gt;
      &lt;/div&gt;  
  &lt;/form&gt;
  &lt;button class="upload-control btn-success btn" type="submit" id='submit-all' onclick="document.getElementById('myDropzone').submit()"&gt;
      &lt;i class="glyphicon glyphicon-upload"&gt;&lt;/i&gt;
      &lt;span&gt;{% trans 'Submit' %}&lt;/span&gt;
  &lt;/button&gt;
  
  &lt;style&gt;
      .upload-control {
          margin-top: 10px;
          margin-bottom: 0px;
      }
  &lt;/style&gt;
  &lt;script src="{% static 'js/dropzone.js' %}"&gt;&lt;/script&gt;
  &lt;script src="{% static 'js/jquery-2.1.4.min.js' %}"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
      Dropzone.autoDiscover = false
      $(document).ready(function() {
          Dropzone.options.myDropzone = {
  
              init : function() {
                  var submitButton = document.querySelector("#submit-all")
                  myDropzone = this;
  
                  submitButton.addEventListener("click", function(e) {
                      e.stopPropagation();
                      e.preventDefault();
                      myDropzone.processQueue();
                  });
  
                  this.on("sendingmultiple", function() {
                      // Figure out what I want here or if I want at all
                  });
  
                  this.on("successmultiple", function(files, response) {
                      window.location.reload();
                  });
  
                  this.on("errormultiple", function(files, response) {
                      // Figure out what I want here or if I want at all
                  });
  
                  }
                  // Do I need this?
                  //myDropzone.on('success', myDropzone.processQueue.bind(myDropzone));
          };
  });    
  &lt;/script&gt;
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>It works now after adding http:// to the url setting.  But when I upload a file it is added to the database, but the file field is blank.  The multivaluedict shows the file when I print it out, but when it is saved to the database the file field has nothing in it.</p>
  
  <p>When I upload one file I get this in request.FILES:</p>
  
  <p><code>&lt;MultiValueDict: {u'file_upload[]': [&lt;InMemoryUploadedFile: normal.PNG (image/png)&gt;]}&gt;</code></p>
  
  <p>When I upload two I get this in request.FILES:</p>
  
  <p><code>&lt;MultiValueDict: {u'file_upload[]': [&lt;TemporaryUploadedFile: normal.PNG (image/png)&gt;]}&gt;</code></p>
  
  <p>Despite being two files it only shows the one, but adds them both to the database (both without files and just ID and creation date).  Also what is TemporaryUploadedFile and InMemoryUploadedFile?</p>
  
  <p>It should have indexes in the u'file_upload[]' when I upload more than one but it doesn't.  I have the settings correct for uploading multiples.</p>
  
  <p>But I can't seem to get them out of the MultiValueDict.  And when I try something like:</p>
  
  <pre><code>for upload in request.FILES:
      client_upload = ClientUpload.objects.create(client=current_client, file_upload=upload)
  </code></pre>
  
  <p>I run into that problem where the admin panel shows an ID and time but no file.  It happens when uploading one or more.  I'm not sure what the difference is between InMemoryUploadedfile and TemporaryUploadedFile either.  How can I extract the files from the MultiValueDict?  get() is not working, with the list comp I just get an empty list.</p>
  
  <p>The other odd thing, is when I upload certain files the MultiValueDict is empty, and with others it is not.  Also it seems that my view gets called more than once (according to the log outputs)  and that is normal, except it should be a post then redirect to a get, but it seems to have more than one post request.  I checked the dev tools in chrome and I only see one, but oddly it outputs my log statement twice for every time I submit.  I know the issue is probably in my view but I've tried a ton of stuff and can't figure out what is wrong.</p>
  
  <p>Anybody have any ideas?</p>