django - 通过RESTful API使用django和tastypie进行文件发布

标签 django rest tastypie

我正在为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

https://github.com/ff0000/django-tastypie/commit/1fbc0a

关于django - 通过RESTful API使用django和tastypie进行文件发布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7193764/

相关文章:

django - 如何在自定义模板中使用 Django 的管理 bool 图标?

python - Celery 任务实例化缓存

Java从列表中获取特定值并添加到其他列表

rest - 如何使用 REST API 获取身份验证 token 或登录 Elastic Search?例如来自 postman

python - Django:防止编辑/删除对象的更干的方法?

javascript - 使用 Backbone.js 从数据库获取完整响应

python - 切换到基于类的 list_detail

java - 如何从 Spring RestTemplate 中的对象获取列表

jquery - Tastypie 不发送 cookie

python - Tastypie 使用自定义 detail_uri_name,类型不匹配错误