python - Save Image generated with Reportlab in my MEDIA folder (in Amazon S3) -
python - Save Image generated with Reportlab in my MEDIA folder (in Amazon S3) -
i implemented library generate barcodes images (http://kennethngedo.wordpress.com/2014/02/07/how-to-generate-barcode-in-django-using-reportlab/)
everything works fine, image generated correctly, but... image created in folder outside project, , such i'm using heroku production, can't access image.
i'm using django construction (http://django-skel.readthedocs.org/en/latest/) specially adapted work on heroku amazon s3.
do know guys how can upload generated image on media folder on amazon?
this views.py image created , saved:
from random import randint reportlab.lib.units import mm reportlab.graphics.barcode import * reportlab.graphics.shapes import drawing, string django.shortcuts import render_to_response class mybarcodedrawing(drawing): def __init__(self, text_value, *args, **kw): barcode = createbarcodedrawing('code128', value=text_value, barheight=10*mm, humanreadable=true) drawing.__init__(self,barcode.width,barcode.height,*args,**kw) self.add(barcode, name='barcode') def barcode_generator(barcode_value): text = barcode_value filename = "nightology_barcode_" + barcode_value path_to_save = "media/barcodes/" b = mybarcodedrawing(text) b.save(formats=['gif','pdf'],outdir=path_to_save,fnroot=filename) barcodepicurl = "barcode/"+ filename + ".gif" homecoming barcodepicurl i hope help me on this... i'll appreciate.
thanks!
i had similar problem without amazon s3 part. me easy create new file in media folder. utilize default_storage path media folder:
from django.core.files.storage import default_storage import os # path barcodes folder in media folder # check if folder exists , create if not folderpath = default_storage.path('barcodes') if not default_storage.exists('barcodes'): os.mkdir(folderpath) since django-skel seems using django-storage backend amazon s3 should work setup. if amazon s3 storage backend not default storage backend, might have utilize s3storage class directly.
python django heroku amazon-s3 reportlab
Comments
Post a Comment