使用 django-piston 发布 JPG|PNG 以及 JSON 描述

发布于 2024-09-28 09:15:11 字数 112 浏览 0 评论 0原文

我正在 django-piston 中定义一个 create() 方法。我需要能够接收图像及其以 JSON 格式编码的描述。怎么做呢?它们应该在两个单独的 HTTP 请求中进行处理吗?

I'm defining a create() method in django-piston. I need to be able to receive and image with its description enconded in JSON. How to do it? Shall they be processed in two separate HTTP requests?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

゛清羽墨安 2024-10-05 09:15:11

我建议将您的文件作为多部分编码表单发布,就像您的网络浏览器通过表单上传文件时所做的那样。通过多部分编码,您可以将文件作为表单中的二进制数据元素发送(比在 JSON 中对 JPG 进行 BASE64 编码要好得多),然后发送另一个保存 JSON 数据的元素。这是一个请求。有很多库可以解析这种形式的内容,因此很容易做到。

I'd suggest posting your file as a multi-part encoded form just like your web browser does when you upload a file through a form. With multi-part encoding you can send the file as binary data element in your form (much better than BASE64 encoding your JPG in JSON), and then another element that holds your JSON data. It's one request. There are plenty of libraries out there that parse things in this form so it's easy to do.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文