.net - 如何将 FormData 对象中的文件从 AngularJS 发布到 ASP.NET
问题描述
我正在尝试使用 HTML2CANVAS 将 html 中的发票页面截图为画布,然后使用 pdfmake 创建一个 pdf,我需要通过 http post 将 pdf 文件发送到后端,我有这个功能:
$scope.createPdf = function () {
html2canvas(document.getElementById('exportthis')).then(canvas => {
var data = canvas.toDataURL();
var docDefinition = {
content: [{
image: data,
width: 500,
}]
};
var file = pdfMake.createPdf(docDefinition)
var Fileblob = file.getBlob((Blob) => {
Blob.lastModifiedDate = new Date();
Blob.name = "Invoice.pdf;"
console.log(Blob);
var fd = new FormData();
fd.append('file', Blob, 'Invoice.pdf');
$http.post("/Home/SendInvoice", {data: fd})
.then(function successCallback(data) { },
function errorCallback(response) {
console.log(response.statusText);
})
.finally(function () {
}
);
});
});
};
我尝试了 FormData 并单独发送 Blob,但它在后端显示为 null。
public JsonResult SendInvoice(HttpPostedFileBase Attachement)
{
//Send Email with the file as an attachement
*
*
return Json("Email Sent", JsonRequestBehavior.AllowGet); ;
}
解决方案
推荐阅读
- laravel - Laravel 测试通过了 auth 中间件,但通过数据提供者的 Auth::user() 失败
- laravel - Laravel mongoDB - jenssegers 嵌套数组更新,将查询转换为在 Laravel 中运行
- logging - 在 Azure Service Fabric 中托管时,使用 AppInsights 从 Python 中的 Flask 日志不显示
- sql - 自定义日期范围参数或 SSRS 下拉菜单中的预定义日期
- excel - VBA:在 IE 中引用图像
- jmeter - 在 Jmeter 中设置场景
- c# - 如何在按钮单击时播放数据库中的音频
- apache-spark - pyspark - 为列表中的多个 id 并行运行 spark sql 查询
- ios - 当我收到推送通知时收到系统警告
- python - 在 Python 中读取 parquet 字节对象