python - Upload photo from Android device to Django backend and save it to database -


i have upload image android device web app written in python , django. storing images, have made use of easy thumbnails.

what have done far convert image base64 string , post server. working perfectly, if write base64 string png image file goes smoothly.

now, want save database far know, easy thumbnails save actual file location on server within app file structure, , saves link same in database.

i not understanding, how save base64 string receive in post database.

my model:

class register(models.model):     image = thumbnailerimagefield(upload_to=filename, blank=true, null=true, max_length=2048)  def filename(inst, fname):    f = sha256(fname + str(datetime.now())).hexdigest()    return '/'.join([inst.__class__.__name__, f]) 

the image not stored in db. stored disk. reference file stored in db.

def article(models.model):     image = models.imagefield(...) 

somewhere create new object:

from django.core.files.base import contentfile  obj = article() data = base64.b64decode(encoded) # might want sanitise `data` here... # maybe check if pil can read `data`? obj.image.save('some_file_name.ext', contentfile(data)) obj.save() 

Comments

Popular posts from this blog

gcc - MinGW's ld cannot perform PE operations on non PE output file -

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

c# - Search and Add Comment with OpenXML for Word -