如何将带有 javascript/jQuery 的二进制文件放入 webdav?

How to PUT a binary file with javascript/jQuery to webdav?

我如何 PUT 一个二进制文件,比如说一个带有 HTTP PUT 请求到 webdav 的图像?我已经试过base64编码了,但是文件坏了

$.ajax({
   url: url + file,
   data:base64content,
   type: 'PUT',
   crossDomain: true,
   headers:{'content-type':'image/png'},
   xhrFields:{withCredentials: true}
});

我在这个网站上找到了一个解决方案: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Sending_and_Receiving_Binary_Data

var oReq = new XMLHttpRequest();
oReq.open("POST", url, true);
oReq.onload = function (oEvent) {
  // Uploaded.
};

var blob = new Blob(['abc123'], {type: 'text/plain'});

oReq.send(blob);