Anonymous avatar Anonymous committed cd4e2a9

download media

Comments (0)

Files changed (5)

 from media import models
 from fileform import FileForm
 from utilities import blob_helper
+import urllib
+import logging
 
 def upload(request):
     form = None
     return render_to_response('admin/upload.html', {'upload_url':upload_url,
 													'upload_error': request.session.pop('upload_error', None),
 													'form': form})
+
+def download(request, key):
+    blob_key = str(urllib.unquote(key))
+    blob = blobstore.BlobInfo.get(blob_key)
+    return blob_helper.send_blob(request, blob, save_as=True)

templates/admin/upload.html

 	{{ form.as_p }}
 	<p>
 	<label for="fileupload">Upload Media :</label>
-	<input type="file" name="media"/><br>
+	<input type="file" id="media" name="media"><br>
 	</p>
 	<p>
 	<input class="submit" type="submit" name="submit" value="Upload">
     (r'^page/delete/([-\w]+)', 'pages.views.delPage'),
 
 	(r'^media/upload/', 'media.views.upload'),
-	
+    (r'^media/download/([-\w]+)', 'media.views.download'),
+
     (r'^contact/$', 'pages.views.contact'),
     (r'^([-\w]+)', 'pages.views.render'),
 )

Binary file modified.

utilities/blob_helper.py

 import cgi
 from google.appengine.ext import blobstore
+from django.http import HttpResponse
+import logging
 
 
 def get_uploads(request, field_name=None, populate_post=False):
     """
 
     CONTENT_DISPOSITION_FORMAT = 'attachment; filename="%s"'
+    logging.info(blob_key_or_info)
     if isinstance(blob_key_or_info, blobstore.BlobInfo):
       blob_key = blob_key_or_info.key()
       blob_info = blob_key_or_info
       blob_key = blob_key_or_info
       blob_info = None
 
-    logging.debug(blob_info)
+    #logging.debug(blob_info)
     response = HttpResponse()
     response[blobstore.BLOB_KEY_HEADER] = str(blob_key)
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.