我正在尝试将用于内容提取的 PDF 发送到 Tika 服务器,但总是收到错误消息:“无法使用源编码从流中转换文本”
这就是 Tika 对文件的期望:
“所有获取文件的服务都使用 HTTP“PUT”请求。使用“PUT”时,原始文件必须在请求正文中发送,无需任何额外编码(不要使用 multipart/form-data 或其他容器)。来源https://wiki.apache.org/tika/TikaJAXRS#Services
使用 XMLHttpRequest() 发送文件的正确方法是什么?
代码:
var response, error, file, blob, xhr;
file = new File("/PROJECT/web/dateien/ai/pdf.pdf");
blob = file.toBuffer().toBlob("application/pdf");
url = "http://localhost:9998/tika";
// send data
try {
xhr = new XMLHttpRequest();
xhr.open("PUT", url);
xhr.setRequestHeader("Accept", "text/plain");
xhr.send(blob);
} catch (e) {
error = e;
}
({
response: xhr.responseText,
status: xhr.statusText,
error: error,
type: xhr.responseType,
blob: blob
});
错误: