2010-03-28 7 views
3

장고와 함께 gae를 사용하고 있습니다. 내가장고를 사용하는 Google 애플리케이션 엔진에서 파일 업로드

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), 
) 

다음 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('<html><body>') 
    response.write('<form action="%s" method="POST" 
enctype="multipart/form-data">' % upload_url) 
    response.write("""Upload File: <input type="file" 
name="file"><br> <input type="submit" 
     name="submit" value="Submit"> </form></body></html>""") 
    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) 

지금 때마다 업로드 사용하여 파일을 가진 MusicFun 내부 응용 프로그램 MusicSite이 있습니다 mapping- 다음 URL을 MusicSite라는 이름의 프로젝트가/시작 제출을 클릭하십시오. 다음 URL이있는 빈 페이지로 이동합니다.

localhost:8000/_ah/upload/ahhnb29nbGUtYXBwLWVuZ2luZS1kamFuZ29yGwsSFV9fQmxvYlVwbG9hZFNlc3Npb25fXxgHDA 

이러한 rando m 개의 알파벳은 다양하게 유지되지만 결과는 동일합니다. 업로드 할 때마다 빈 페이지가 표시됩니다. 누군가 도와주세요.

서버 응답

이 같은 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 - 

답변

3

업로드 핸들러가 반환 500 :

예외를 던지는 때문에이 거의 확실하다
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. 

; 당신은 장황한 상황을 볼 수 있도록 예외를 로그하도록 장고를 설득 할 필요가있다. 번갈아 가며 잡아서 직접 로그인하십시오!

관련 문제