有人可以给我一些代码(iOS方面和Django方面)向我展示如何让iOS将图像上传到Django,Django将其重命名并保存在/ static /文件夹中。
这是我的Django模型
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))
但我真的不知道:iOS如何使用POST或PUT将一个图像上传到Django和Django重命名并保存。可以使用一些片段(iOS端和Django端)