【问题标题】:How to PUT a binary file with javascript/jQuery to webdav?如何将带有 javascript/jQuery 的二进制文件放入 webdav?
【发布时间】:2019-06-24 11:17:05
【问题描述】:

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

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

【问题讨论】:

    标签: ajax encoding request put webdav


    【解决方案1】:

    我在这个网站上找到了一个解决方案: 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);
    

    【讨论】:

      猜你喜欢
      • 2017-03-20
      • 1970-01-01
      • 2022-11-18
      • 2010-11-13
      • 2022-01-04
      • 2020-06-07
      • 2012-12-25
      • 1970-01-01
      • 2013-05-29
      相关资源
      最近更新 更多