Last active
August 4, 2016 15:08
-
-
Save bradleyg/919fe0eb891fa99492a7cb49097c2484 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# index.html | |
<form class="" enctype="multipart/form-data" action="{{ upload_url }}" method="post"> | |
<input type="file" name="file" id="file"><input> | |
<input type="submit" name="submit" value="Upload"> | |
</form> | |
# urls.py ----------------------------------- | |
from django.conf.urls import url | |
from .views import UploadFormView, UploadFileView | |
urlpatterns = ( | |
url(r'^$', UploadFormView.as_view(), name='upload_url'), | |
url(r'^upload/$', UploadFileView.as_view(), name='upload'), | |
) | |
# view.py ----------------------------------- | |
import json | |
from django.views.generic import View, TemplateView | |
from django.http import HttpResponse | |
from django.core.urlresolvers import reverse | |
from google.appengine.ext import blobstore | |
class UploadFormView(TemplateView): | |
template_name = 'index.html' | |
def get_context_data(self, *args, **kwargs): | |
ctx = super(UploadFormView, self).get_context_data(*args, **kwargs) | |
ctx['upload_url'] = blobstore.create_upload_url(reverse('upload')) | |
return ctx | |
class UploadFileView(View): | |
def post(self, request): | |
image = request.FILES.get('file') | |
data = image.blobstore_info.open() | |
# ... whatever you need to do with PDF | |
return HttpResponse(data.read(), content_type="image/png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment