2

Could someone give me some code (iOS side and Django side) to show me how to let iOS upload the image to Django, and Django rename it and save it in the /static/ folder.

  • This is my Django Model

    class UserAccountInfo(models.Model):
        usignup_email = models.EmailField(blank=False)
    
        def __unicode__(self):
            return "UserAccountInfo: user signup email = ", str(self.usignup_email)
    
    
    def cal_image_path(instance, image_title, image_size_category):
            filename = str(image_title) + '_' + str(image_size_category) + '.png'
            return os.path.join('users', str(instance.usignup_email), filename)
    
    
    class UserImages(models.Model):
            uid = models.ForeignKey(UserAccountInfo)
            uimage_title = models.CharField(max_length=70)
            uimage_size_category = models.IntegerField()
            uimage = models.ImageField(upload_to=cal_image_path, blank=True, null=True)
    
           def __unicode__(self):
                 return "UserImages: image title = %s, image size category = %s"\
                   % (self.uimage_title, str(self.uimage_size_category))
    

But I really have no idea: how iOS using POST or PUT to upload one image to Django and Django rename it and save it. Could some snippets(iOS side and Django side)

zproject89
  • 225
  • 5
  • 19
  • The iOS part in this question is irrelevant. Make it work for the web and it will work for a phone/tablet. Also, there's plenty of examples of file upload on the web, including this excellent [answer on SO](http://stackoverflow.com/questions/5871730/need-a-minimal-django-file-upload-example). Duplicate. Voting to close. – Nil Mar 16 '14 at 23:17
  • Thank you so much, I have figure out. – zproject89 Mar 16 '14 at 23:58
  • @Peter I want to do something like this too, could you pls show me how to do this? – Demonedge Dec 23 '15 at 08:29

0 Answers0