google app engine - Using images uploaded to the blobstore using Django-nonrel and file-transfer application -
i building blog site in google app engine, using django-nonrel , need way store , display images in blog posts etc.
the idea have upload application upload images specific articles etc, , use absolute or relative url imd src.
i using django-filetransfers upload images (http://www.allbuttonspressed.com/projects/django-filetransfers).
questions are: 1) using google app engine , django-nonrel host blog? if how , storing images? using gae blobstore use overkill? 2) image url using download path set in flie-transfers application. eg. correct? seems bit weird not reference using .png extension or anything. might way reference images blobstore?
still learning rope django , google app engine appreciated.
thanks
can,
i have had similar experience in using blobstore django-nonrel.
for first question, blobstore not overkill , think in fact way can upload image without updating whole project , republishing it. gae not let write directory because of server's high replication , security. it's trade off being able spin servers automatically demand increase. if try involves writing directory, app engine error.
i looking better solution second question myself. able reference file name myself. key think adding attribute "upload" model gets set filename @ save time. have not tried should work.
update:
this worked.
here model:
class uploadmodel(models.model): title = models.charfield(max_length=64, blank=true) file = models.filefield(upload_to='uploads/%y/%m/%d/%h/%m/%s/') filename = models.charfield(max_length=100, editable=false, null=true, blank=true) def save(self, *args, **kwargs): self.filename = self.file.name.rsplit('/', 1)[-1] super(uploadmodel, self).save(*args, **kwargs)
here download handler:
def download_handler(request, filename): upload = get_object_or_404(uploadmodel, filename=filename) return serve_file(request, upload.file, save_as=true)
the url mapping:
url(r'^file/(?p<filename>.+)$', 'cms.views.download_handler_filename', name='cms-download_file'),
once can access file filename (this snippet example app). can see 'pk' replaced 'filename' attribute:
{% url cms-download_file filename=upload.filename fallback_url %} <p><img src="{% firstof upload.file|public_download_url fallback_url %}"></p>
what stuck on myself getting 'public_download_url' work gae blobstore. if else can comment in how proper public backed work automatically generates public url appreciate it.
grant
Comments
Post a Comment