Giter Club home page Giter Club logo

django-jquery-file-upload's Introduction

jQuery-File-Upload is developed by Sebastian Tschan, with the source available on github. Example code is ported to Django by Sigurd Gartmann (sigurdga on github).

Introduction

This is a small example on how to setup Sebastian Tschan's jQuery File Upload in Django. He has a working demo on his webpage and a github repository with an example on how to do it in PHP.

Here, you'll find a minimal Django project with a minimal app. You can run the example standalone by cloning the repository, running the migrations and starting the server.

I want to give a thank to Sebastian Tschan, the original author, Etay Cohen-Solal, for the latest major update, and Jørgen Bergquist for helping me over the first hurdles.

Features

  • Drag and drop files
  • Select multiple files
  • Cancel upload
  • Delete uploaded file (from database only)
  • No flash (or other browser plugins) needed
  • … more at the upstream's features page

Requirements

  • Django
  • Python Imaging Library

If you do not get PIL to work (pillow is a replacement package that works with virtulalenvs), use FileField instead of ImageField in fileupload/models.py as commented in the file.

Installation

I recommend to install this within a virtualenv.

virtualenv -p python3 venv
source venv/bin/activate
pip install -r requirements.txt
./manage.py migrate
./manage.py runserver

And then go to localhost:8000 and try to upload some files.

License

MIT, as the original project. See LICENSE.txt.

django-jquery-file-upload's People

Contributors

dependabot[bot] avatar dolgiyspb avatar et-cs avatar ikonitas avatar mattchatterley avatar sigurdga avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-jquery-file-upload's Issues

Two missing files:

The file static/img/loading.gif seems to be missing from the repository as well as the file templates/fileupload/picture_confirm_delete.html.

The error below can be generated with the django development server by passing in a URL like http://localhost:8000/upload/delete/1

TemplateDoesNotExist
Exception Value:    
fileupload/picture_confirm_delete.html
Exception Location: /Library/Python/2.7/site-packages/django/template/loader.py in select_template, line 193

Required field... how?

Hello,
I have a problem with required field... I downloaded the application and everything was fine... then I tried to add in models.py a simple required field like this

test = models.CharField(max_length=60,)

First attempt gave me, as expected because I didn't try to give to the new field some value, this error:

{"test": ["This field is required."]}

Second attempt I added a line to the save method in models.py (replicating what is done for the slug field)

def save(self, *args, **kwargs):
    ...
    self.test = 'foo'

same error... Third attempt (after a LOT of googling) I changed views.py like this

def form_valid(self, form):
    self.object = form.save(commit=False)
    self.object.test = "foo"
    self.object.save()
    ...

again the same error... I don't know now what to do... any suggestion?

Thanks

south app missing

The code includes a south migration, but the app is not listed.

Need to add 'south' to INSTALLED_APPS in settings.py

p.s. nice work! works first time (almost), and the code is concise and clear. Thanks

Please package

Please package this app with a setup.py script. Would be nice if it was on pypi as well. Thanks!

DeprecationWarning:

As soon as I upgraded to Django 1.6 I started to get this deprecation warning:
[..]/site-packagesjfu/http.py:2: DeprecationWarning: django.utils.simplejson is deprecated; use json instead. from django.utils import simplejson

Easily fixable by replacing:
from django.utils import simplejson
with:
import json

Cheers!

ImportError: No module named django-jquery-file-upload.urls

Hi,

When I try to see the page in chrome it says:

ImportError at /upload/new/
No module named django-jquery-file-upload.urls
Request Method: GET
Request URL: http://127.0.0.1:8000/upload/new/
Django Version: 1.5.4
Exception Type: ImportError
Exception Value:
No module named django-jquery-file-upload.urls
Exception Location: /usr/lib/python2.7/dist-packages/django/utils/importlib.py in import_module, line 35
Python Executable: /usr/bin/python
Python Version: 2.7.5
Python Path:
['/home/desenvolvedor/Downloads/django-jquery-file-upload-master',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-i386-linux-gnu',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages/PILcompat',
'/usr/lib/python2.7/dist-packages/gtk-2.0',
'/usr/lib/pymodules/python2.7',
'/usr/lib/python2.7/dist-packages/ubuntu-sso-client',
'/usr/lib/python2.7/dist-packages/ubuntuone-client',
'/usr/lib/python2.7/dist-packages/ubuntuone-control-panel',
'/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol']
Server time: Wed, 29 Jan 2014 12:23:40 -0600

Cross-Domain POST not working

When doing a cross-domain POST, an OPTIONS request is issued first. This application does not send a proper response for OPTIONS, thus causing the subsequent POST to fail.

I have this project running on my WebFaction account at: http://uploader.btaylordesign.webfactional.com, and am attempting to post from a static, JavaScript application running in Nginx on my local computer.

TemplateSyntaxError at /admin/fileupload/picture/ Caught TypeError while rendering: coercing to Unicode: need string or buffer, FieldFile found

django-jquery-file-upload works fine. the problem is in the admin panel using django 1.3.4 from EPEL on centos 6.3 minimal.

When I get inside the admin panel - into the 'picture' table when it's empty, - everything is fine. when there are rows - it return error 500. with DEBUG:

TemplateSyntaxError at /admin/fileupload/picture/
Caught TypeError while rendering: coercing to Unicode: need string or buffer, FieldFile found

the def unicode for the model is set to return self.file. which django dosen't accept.
when I am changing it to self.slug - everything works fine again in the admin panel but the jquery uploader stops working.

Wrong link when file name have space

When user upload a file with a blank space filename (ex: "my pic.jpg") the file is saved with underscores instead black spaces but the link is pointing to the original file name with blank space giving a 404 error

Additional form fields with file upload

Hi

Thanks for writing this example with Django. It works out of the box, but how would you change the code if you need to add a 'description' field for each file that you upload.

I have changed the upload-template in the upload_tags.py file to render the additional text field named 'description':

        <tr class="template-upload{{if error}} ui-state-error{{/if}}">                    
            <!-- <td class="name">${name}</td> -->                                        
            <!-- <td class="size">${sizef}</td> -->                                       
            <td class="preview"></td>                                                     
            {{if error}}                                                                  
                <td class="error" colspan="2">Error:                                      
                    {{if error === 'maxFileSize'}}File is too big                         
                    {{else error === 'minFileSize'}}File is too small                     
                    {{else error === 'acceptFileTypes'}}Filetype not allowed              
                    {{else error === 'maxNumberOfFiles'}}Max number of files exceeded     
                    {{else}}${error}                                                      
                    {{/if}}                                                               
                </td>                                                                     
            {{else}}                                                                      
                <!-- <td class="progress"><div></div></td> -->                            
                <td class="start" style="display:none;" ><button>Start</button></td>      
                <td class="file_upload_desc"><input type="text" name="description"/></td>\

                <td class=""><select name="photo_type"><option>restaurant</option></selec\
t></td>                                                                                   
            {{/if}}                                                                       
            <td class="cancel"><button>Cancel</button></td>                               
        </tr>                                                                             

The field renders correctly with each file row but the POST data that reaches the server never contains the additional field.

I read the jquery-file-upload docs and found out about formData but could not figure out how to initialize it with different data for each row (file).

Any help will be appreciated.

Jai

Mod Python

Works amazing running the dev server, however when I try to add it to my httpd.conf and run it with mod python, i get an import settings error. Any help?

 <Directory "/Library/WebServer/Documents/pictureupload">
    SetHandler python-program
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE pictureupload.settings
    PythonDebug On
    PythonOption django.root /pictureupload/upload/new
</Directory>

Problem when trying to upload file to AppEngine

I'm trying to make it work on AppEngine. I had success deploying and it works until I try to upload, an error message shows in server log:

ValueError: The App Engine storage backend only supports BlobstoreFile instances or File instances whose file attribute is a BlobstoreFile.

I believe that the error is because in models.py it uses django's model class, which is models.FileField, but AppEngine requires db.Blob().

Any idea to fix it? Thanks.

ROOT_URLCONF string is "wrong"

Hey - great code very helpful thanks for contributing. Just letting everyone know that I encountered a small issue while compiling the source code - the ROOT_URLCONF in "settings.py" should be django-jquery-file-upload-master.urls, not django-jquery-file-upload.urls. With the wrong string the code gives a module import error. Thanks again!

DELETE causes 403 Forbidden errors

Initial install works fine for adding. Deleting removes the image from the client side, but the server throws 403 forbidden error and never reaches PictureDetailView.delete (so the database record does not get deleted):

[29/Jun/2012 23:02:22] "DELETE /upload/delete/11 HTTP/1.1" 403 2294

Any pointers greatly appreciated.

This is using basic "manage.py runserver" (rather than nginx) on Django 1.4.

Problem with form.save()

def form_valid(self, form):
    self.object = form.save()
    f = self.request.FILES.get('file')

I'm changing my file name. so i get the "INTERNAL SERVER ERROR".
Can you tell a better way where i can get the changed name in the next step.

Instead of requesting the file. I want to request the DB.

Upload/Start button not working if url is changed

I am create a image gallery project using this app .

and my url :

url(r'^(?P<album_pk>\d+)/$', AngularVersionCreateView.as_view(), name='upload-angular'),

I did not do any other changes but it upload url shows still 'http://localhost:8000/upload/angular/'

how can i dynamically assign 'album_pk' to the upload button. What other changes i have to do while doing this . Where the url is hard coded

i request someone support to do this. i was working django 1.3. So i am not good in the class level view and other stuff in the code base.

Update js files

Hello sigurdga.

I want to update to latest version of the js files from the source demo project: blueimp / jQuery-File-Upload. https://github.com/blueimp/jQuery-File-Upload

It will be very helpful, and will saves me a lot of time, if I knew what changes you've made to the files, if any, when creating this wonderful project.

Thank you in advance,
ET.

reverse url returns Internal Server Error

I get the uploaded file in the directory specified, however, nothing is saved in the database. And I see Internal Server Error on the UI error message.
I narrowed the error down and found out that there is something with the url that I cannot figure out. For some reason the reverse function reverse('upload-delete', args=[self.object.id] causes the error.
What might be the problem?

Thanks

Image Resize Works on Firefox but not on Chrome and Safari

Hi Sigurd,

Excellent example!
After cloning, I uncommented this section to enable image resize:
{ action: 'load', fileTypes: /^image\/(gif|jpeg|png)$/, maxFileSize: 20000000 // 20MB }, { action: 'resize', maxWidth: 1024, maxHeight: 768, minWidth: 800, minHeight: 600 }, { action: 'save' }

This works well in Firefox (v21.0) but this doesn't seem to work in Chrome (v27.0.1453.94) and Safari (v5.1.7).
Is this expected? Would you know if updating with the latest js files from https://github.com/blueimp/jQuery-File-Upload will fix this issue?

Thanks,
Kenneth

Multiple file upload doesn't seem to work

I'm playing around with your Django app and everything seems to be working just fine.
Except I'm not able to upload more than one file at once. If I select more than one file, only the first file is shown and uploaded to the server.

I'm not getting any exceptions or errors, so it's quite difficult to figure out what is actually happening. Any idea?

from django.conf.urls.defaults import patterns, url

I have several commits I'd like to add soon:

  • upgrade to newer files version of the Jquery-File-Upload. many things changed and new feautres added.
  • Maybe add the different versions: Basic, Basic Plus, Basic Plus UI, AngularJS, jQuery UI

I would like to make my repo the same as yours to be able to commit changes without need to apply fixes.

from the comparison of your master against my master:
https://github.com/ET-CS/django-jquery-file-upload/compare

there are two differences:

1:
picture_form.html ->
the div fileupload-content used by you to render the files from django.
... and ...
the def get_context_data() function .
Which both are not implemented now and can be removed in next merge?


2:
in fileupload/urls.py:

-from django.conf.urls import patterns, url

+from django.conf.urls.defaults import patterns, url

removing .defaults generates error for me. I guess its django version compatibility issue.. (I am using Django 1.3.7 from CentOS repo)

Any idea how to fix this and to support both django versions?

Question: How is the default template loaded?

Hi,

This is not really an issue but more of a question. (I am kind of new to Django...) I can't find anywhere in your code where the template "picture_form.html" is loaded... I don't understand how it does it?!

Also, why do you need super() here?

 super(Picture, self).save(*args, **kwargs)

Thanks a lot,

Antoine

Error: SyntaxError: Unexpected token ILLEGAL

After clicking start upload, but before the actual save, this error message appears next to file: "Error: SyntaxError: Unexpected token ILLEGAL". Happens in your demo and also in my own implementation.

Not able to upload csv files

Hi sir,

I am not able to upload csv files using either basic or basicplus or basicpluswithui

Images work fine. But csv or other files dont. I changed something and it doesnt do what I thought it would.

Looking at some questions on stackoverflow, I changed

acceptFileTypes: /(.|/)(gif|jpe?g|png)$/i
to this
acceptFileTypes: /(.|/)(gif|jpe?g|png|csv)$/i

at this location project/fileupload/templates/fileupload/picture_basicplus_form.html

I tried this parameter in main.js and other js files, to no effect.

The project is here right now....
http://detectphonenumbers.yesiknowjava.webfactional.com/upload/basic/plus/

Is there anything else I need to do in any other file. As this change does not store the csv file anywhere

Can somebody please help. Also I request the author to put up a simple integration instead of class based views, collectstatic and all the other steps.
Like step 1 include this css,js in template head section
step 2 put this html in the body section
step 3 ok here is views function (not generic view)

Problem when trying to host on AppEngine

I'm trying to make it work on AppEngine. I had success deploying and it works until I try to upload, an error message shows in server log:

ValueError: The App Engine storage backend only supports BlobstoreFile instances or File instances whose file attribute is a BlobstoreFile.

Any idea, since I believe its uploading a blob, right?

Generating URL to share uploaded files

HI all
I was wondering if there's a way we could generate an url to share the uploaded files, and along with that if we can set some time constraint as how much time that url should persist.. Please do respond :) Thank You :)

Suggestion for adding new data fields to the model

I was messing around with you app, its great. However I am having a little difficulty adding new fields, specifically datetime fields and url fields. I thought it would be good if there was a timestamp of some sort upon uploading the picture, however json seems to be having issues with the datatime field and the url field...suggestions?

Problem with User Field

Hello!

I have problem with uploads files. I add user field:

class Picture(models.Model):
user = models.ForeignKey(NormalUser)
file = models.ImageField(upload_to="pictures")

I found this solution for views.py in internet:

class PictureCreateView(CreateView):
model = Picture
fields = "all"

def form_valid(self, form):
    self.object = form.save(commit=False)
    self.object.user = self.request.user
    self.object.save()
    files = [serialize(self.object)]
    data = {'files': files}
    response = JSONResponse(data, mimetype=response_mimetype(self.request))
    response['Content-Disposition'] = 'inline; filename=files.json'

    return response

But when I add image i see this:

unt

Application don't upload file. Stop in 100%. What is the problem?

Thank You!
efeniks

High memory usage

When I upload files to server it increases memory usage a lot even when I upload small files. Even when I close and reopen webpage, the memory usage is still high, even if i uploaded five small files on server. Is the problem on my side?? How can I Repair it? I didn’t change the example yet. I am using django 1.6 branch.

Merge with error

I've merged João Paulo Dubas's commits. I liked the serializer and response objects. The view.py file is cleaner that way .I've checked for problems before the merge but I forgot to check the /upload/view (Loading already uploaded images on load). And there is error there:
init() takes exactly 1 argument (2 given)
Now, the loading of already uploaded pictures is not working.
I can't find the source of the problem, and I don't have lot of time this week. You know what the problem is? or it is better to go back to commit 2ec7f80
Sorry for the mistake.

Changing model field names for file

Having a little trouble following the javascript code. I wanted to create an additional field in the model called: file_2

Then before uploading the file, have the javascript detect if the file is not an image.

If it is an image it uploads the file to the normal file field.
// file = ImageWithThumbsField(upload_to='filefolder', sizes=((75,75),(120,120)), null=True, blank=True)

If the file being uploaded is not an image, then it would use file_2
// file_2 = models.FileField(upload_to='filefolder', null=True, blank=True)

ImageWithThumbsField is working and I can see how detect for an image...just having trouble seeing how the javascript would change the file field name parameter to file_2

Thanks!

Internal Server Error while uploading images

I was trying it on the apacher server by using django sever with WSGI
The server gives me an internal server error everytime I try to upload the images, however the images are being stored in the /media/pictures folder.

Can you help me solve this issue. I have attached the screenshot as well
internalerror

thanks in advance

Solved: Permissions were incorrect.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.