我正在为Django网站创建RESTful API。我正在使用tastypie来做到这一点。我的问题是我无法设计如何通过此api发布图像或文件。我的意思是,要在数据库上创建对象,我们以json格式发布数据。但是我怎么能在json里面放一个文件呢?
我发现有两种方法,其中一种是将它们转换为Base64格式。我不想使用它,因为在我的测试中,当转换为Base64时,74kb的镜像为110kb-120kb。
因此,有人可以向我解释一下如何发布其中包含文件的对象吗?
最佳答案
在这里看:https://github.com/toastdriven/django-tastypie/issues/42
看起来有办法做到这一点,但效果并不理想。
After a long time playing around with various solutions ( https://github.com/klipstein/django-tastypie/commit/e0f86ddffeb46c77704328a3b5899ec08e18e4eb, https://github.com/klipstein/django-tastypie/commits/form-data) doing file-handling within tastypie I came to the conclusion that this can't be solved elegantly if you want to support file uploads from every browser.
看看这把 fork
关于django - 通过RESTful API使用django和tastypie进行文件发布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7193764/