File Uploading In Google Application Engine Using Django
Posted
by Ayush
on Stack Overflow
See other posts from Stack Overflow
or by Ayush
Published on 2010-03-28T08:00:26Z
Indexed on
2010/03/28
8:03 UTC
Read the original article
Hit count: 533
I am using gae with django. I have an project named MusicSite with following url mapping-
urls.py
from django.conf.urls.defaults import * from MusicSite.views import MainHandler from MusicSite.views import UploadHandler from MusicSite.views import ServeHandler
urlpatterns = patterns('',(r'^start/', MainHandler), (r'^upload/', UploadHandler), (r'^/serve/([^/]+)?', ServeHandler), )
There is an application MusicSite inside MusicFun with the following codes-
views.py
import os import urllib
from google.appengine.ext import blobstore from google.appengine.ext import webapp from google.appengine.ext.webapp import blobstore_handlers from google.appengine.ext.webapp import template from google.appengine.ext.webapp.util import run_wsgi_app
def MainHandler(request):
response=HttpResponse()
upload_url = blobstore.create_upload_url('http://localhost:
8000/upload/')
response.write('')
response.write('' % upload_url)
response.write("""Upload File:
""")
return HttpResponse(response)
def UploadHandler(request): upload_files=request.FILES['file'] blob_info = upload_files[0] response.redirect('http://localhost:8000/serve/%s' % blob_info.key())
class ServeHandler(blobstore_handlers.BlobstoreDownloadHandler): def get(self, resource): resource = str(urllib.unquote(resource)) blob_info = blobstore.BlobInfo.get(resource) self.send_blob(blob_info)
now whenever a upload a file using /start and click Submit i am taken to a blank page with the following url-
localhost:8000/_ah/upload/ahhnb29nbGUtYXBwLWVuZ2luZS1kamFuZ29yGwsSFV9fQmxvYlVwbG9hZFNlc3Npb25fXxgHDA
These random alphabets keep varying but the result is same. A blank page after every upload. Somebody please help.
The server responses are as below-
INFO:root:"GET /start/ HTTP/1.1" 200 - INFO:root:"GET /favicon.ico HTTP/1.1" 404 - INFO:root:Internal redirection to http://localhost:8000/upload/ INFO:root:Upload handler returned 500 ERROR:root:Invalid upload handler response. Only 301, 302 and 303 statuses are permitted and it may not have a content body. INFO:root:"POST /_ah/upload/ ahhnb29nbGUtYXBwLWVuZ2luZS1kamFuZ29yGwsSFV9fQmxvYlVwbG9hZFNlc3Npb25fXxgCDA HTTP/1.1" 500 - INFO:root:"GET /favicon.ico HTTP/1.1" 404 -
© Stack Overflow or respective owner