Jer*_*ard 5 javascript python django file-upload tastypie
我在开发带有tastypie的api时遇到了问题.我想要的主要是知道是否有办法直接将图像发布到json内的tastypie.
在我的模型中,我现在正在使用ImageField:
class MyClass(models.Model):
description = models.TextField()
user = models.ForeignKey(User)
photo = models.ImageField(upload_to="image", null=True, blank=True)
Run Code Online (Sandbox Code Playgroud)
然后在我的api文件中:
class InquiryResource(ModelResource):
user = fields.ForeignKey(UserResource, 'user' ,full=True)
photo = fields.FileField(attribute = 'photo', null=True, blank = True)
class Meta :
queryset = MyClass.objects.all()
resource_name = "MyClass"
authorization = Authorization()
Run Code Online (Sandbox Code Playgroud)
当我发送一个只有用户和描述的基本json时,它运行良好.然后当我去添加关于我的图像的信息时:
{ ... ,
photo : {
Content-Type : "image/png",
file : "base64string", <----- this one contains the file as a long string
name : "test.png"
} ...}
Run Code Online (Sandbox Code Playgroud)
我收到一条错误消息:'dict'对象没有属性'_commited'
使用tastypie本地上传文件是否有"干净的方式",还是应该使用Base64FileField?
谢谢
是的,您可以只使用 Base64FileField:https://gist.github.com/jstarcher/ef8d91b8e8d058178f20
了解更多相关信息:https://github.com/toastdriven/django-tastypie/issues/42
| 归档时间: |
|
| 查看次数: |
1150 次 |
| 最近记录: |