It looks like you're new here. If you want to get involved, click one of these buttons!
{% extends 'base/index.html' %}
{% block stylesheet %}
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}uploadify/uploadify.css">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}uploadify/jquery.uploadify-3.1.min.js"></script>
<script type="text/javascript">
$('#file_upload').uploadify({
swf: '{{ STATIC_URL }}uploadify/uploadify.swf',
uploader: '/upload/',
cancelImage: '{{ STATIC_URL }}uploadify/uploadify-cancel.png',
checkExisting: false,
postData: {sessionid: $.cookie('sessionid')},
auto: true
});
</script>
{% endblock %}
{% block content %}
<form>
<input type="file" name="file_upload" id="file_upload" />
</form>
{% endblock %}
url(r'^upload/', 'gallery.views.upload',name='upload'),
def upload(request):
if request.method == 'POST':
for field_name in request.FILES:
uploaded_file = request.FILES[field_name]
#writing the file into destination folder
destination_path = '/home/teioch/dev/knausbook/knausbook/media/gallery/pictures/%s' % (uploaded_file.name)
destination = open(destination_path, 'wb+')
for chunk in uploaded_file.chunks():
destination.write(chunk)
destionation.close()
#indicate that everything is OK for SWFUpload
return HttpResponse("ok", mimetype="text/plain")
else:
#show the upload UI
return render(request, 'gallery/upload.html',{})
from django.conf import settings
from django.core.urlresolvers import reverse
class SWFUploadMiddleware(object):
def process_request(self, request):
if ((request.method == 'POST') and
(request.path == reverse('gallery.views.upload')) and
request.POST.has_key(settings.SESSION_COOKIE_NAME)):
request.COOKIES[settings.SESSION_COOKIE_NAME] = request.POST[settings.SESSION_COOKIE_NAME]
MIDDLEWARE_CLASSES = (
[...]
'gallery.swfupload.SWFUploadMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
)