如何强制 CouchDB 返回 base64 格式的附件而不是 MIME 多部分/相关的附件?

发布于 2024-12-27 04:34:04 字数 657 浏览 3 评论 0原文

http://wiki.apache.org/couchdb/HTTP_Document_API#Getting_Attachments_With_a_Document 中所述,我可以要求通过以下方式将附件连同文档附件一起退回?attachments=true

问题

正如 CouchDB wiki 所说,附件可以以纯 JSON 或 MIME 多部分/相关形式返回。

要获取 MIME 多部分/相关响应格式,只需将“Accept:”标头添加到 请求的值为“multipart/related”。

对我来说,它们总是以 MIME 多部分/相关模式返回,即使没有指定 Accept: 标头也是如此。也许网络浏览器添加了它,但我也无法删除它 - 我需要纯 JSON(用 javascript 处理它们)

问题

我应该怎么做才能获取附件内联,-或者-这是一个 CouchDB 错误吗?

As described in http://wiki.apache.org/couchdb/HTTP_Document_API#Getting_Attachments_With_a_Document , I can ask to return attachments together with the document attachments via ?attachments=true.

The Problem

As the CouchDB wiki states, attachments can be returned either in plain JSON or MIME multipart/related.

To get MIME multipart/related response format, just add an "Accept:" header to the
request with value "multipart/related".

For me, they are always returned in MIME multipart/related mode, even when no Accept: header is specified. Maybe web browser adds it, but I can't remove it either - and i need plain JSON (to process them with javascript)

The Question

What should I do to get attachments inline, -or- is this a CouchDB bug?

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

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

发布评论

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

评论(1

酒几许 2025-01-03 04:34:04

默认情况下,Web浏览器会设置

Accept: */*

因此,正确的方法是预先重置Accept标头:

$.ajax({
beforeSend: function(req) {
    req.setRequestHeader("Accept", "");
    req.setRequestHeader("Accept", "application/json");
},
type: "GET",
url: "/db/doc/?attachments=true&rnd=_"+(new Date().getTime()),
contentType: "application/json; charset=utf-8",
success: function(data) {
    $("#test").html(JSON.stringify(data));
},
error:function(xx,s,x){alert("e"+x.message+" "+x+" "+s);},
});

By default, the webbrowser sets

Accept: */*

So, the correct way is to reset the Accept header beforehand:

$.ajax({
beforeSend: function(req) {
    req.setRequestHeader("Accept", "");
    req.setRequestHeader("Accept", "application/json");
},
type: "GET",
url: "/db/doc/?attachments=true&rnd=_"+(new Date().getTime()),
contentType: "application/json; charset=utf-8",
success: function(data) {
    $("#test").html(JSON.stringify(data));
},
error:function(xx,s,x){alert("e"+x.message+" "+x+" "+s);},
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文