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 -