0

I followed this post jQuery get the image src but it solved my problem partially.

When i get the path of the initial src of img it give me:

/static/app_name/src/blank.png

which is true.

But when i load another image using <input type="file"> and prompt the full path it give me this:

data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCAE+AbMDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwDyrNPT3qOlWvMRkS544oB5+lID1oXJNWhDwM9aXHFHQUmcitEA1hxzUeOakJpueaYgC4p4XjrQpFPXpVoLjdgp6rinBc1IFwKuIEJTB6VGQM1ORTVjLkheaTGhiR5p4j68VLCmBzUhUY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o/DHjJ47LxhbIRp+qbQPPI/hPqT3Xv1GD
Community
  • 1
  • 1
Shift 'n Tab
  • 8,808
  • 12
  • 73
  • 117
  • That's because the image is not yet uploaded to the server, so the browser converts it to a base64 string. What exactly is the expected outcome? – Jonas Grumann Sep 06 '16 at 09:38
  • Oh thanks for pointing out but I would like to get `fullpath` of the img src that is upload from `` – Shift 'n Tab Sep 06 '16 at 09:42
  • ok once you selected the image in the browser and have clicked on upload, the image needs to go to the django app that stores it and then returns the url to it. – Jonas Grumann Sep 06 '16 at 09:48
  • How can i do that sir? since im new to django i dont have any experience yet – Shift 'n Tab Sep 06 '16 at 09:49
  • You'll need a django form, a django model, and a django view for the back end. In the front end you'll need to upload a file (I suggest using an asynchronous call), it's easier to setup if you use jQuery. The template will render the django form, when you submit it the file goes to the django view which will save the model. if you do this asynchronously you can just send back the file path in a json string and render that in the template. http://stackoverflow.com/questions/16540723/django-ajax-file-upload – Jonas Grumann Sep 06 '16 at 09:56
  • Sorry but it's a broad question and stackoverflow is not the place for "I don't know how to do this, how can I do it?". Read the stackoverflow guidelines and come back when you have a more specific problem. – Jonas Grumann Sep 06 '16 at 09:57
  • I can do the saving workaround of a model data to database but its trouble me saving image locally but sure i will update the question as possible it can be – Shift 'n Tab Sep 06 '16 at 10:01
  • What do you mean "locally"? Can you explain what exactly you want? What does your app do? – Jonas Grumann Sep 06 '16 at 10:01
  • Oh i think i have a wrong term here as a beginner, i would like to save the image of html `img` element to the folder `/static/app_name/employee/img/` – Shift 'n Tab Sep 06 '16 at 10:04
  • for that there's the upload_to parameter in the django FileField https://docs.djangoproject.com/ja/1.10/ref/models/fields/#django.db.models.FileField – Jonas Grumann Sep 06 '16 at 10:05

0 Answers0