我已经使用JSRepoprts库生成了PDF报告。输出结果是一个Blob,可以将其下载到“下载”文件夹中。我需要做的是将Blob保存在服务器上的特定文件夹中。我尝试使用XMLHttpRequest发送Blob,但是我在控制器中接收到具有空内容的请求。
我写的代码如下
jsreports.export({
format: 'pdf',
report_def: def,
datasets: data_sources,
outputHandler: function (pdfBlob) {
$('.report-output-pdf').attr('src', URL.createObjectURL(pdfBlob));
var xhr = new XMLHttpRequest();
xhr.open('GET', '/reports/saveReport', true);
xhr.onload = function () {
console.log(xhr.responseText);
};
xhr.send(pdfBlob);
}
});
在服务器端(MVC控制器),代码为:
public ActionResult saveReport()
{
try
{
var r = Request;
int l = Request.ContentLength; // Received 0
byte[] ba = r.BinaryRead(r.ContentLength);
return Json(r, JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
return Json(new { Message = ex.Message }, JsonRequestBehavior.AllowGet);
}
}
有人能通过上面代码的更正或任何其他想法帮助我将pdf blob保存到特定目录吗?