背景: 我有一个AngularJS前端上传文件到ASP.NET后端。我有一个自定义的MultipartStreamProvider,它将数据持久化到Azure。我现在唯一的问题是现有的角度代码没有提交文件大小,只有内容处置标题中的文件名
MyMultipartFormDataStreamProvider : MultipartStreamProvider
{
// ...
public override Stream GetStream(HttpContent parent, HttpContentHeaders headers)
{
// For form data, Content-Disposition header is a requirement
ContentDispositionHeaderValue contentDisposition = headers.ContentDisposition;
if (contentDisposition != null)
{
// create default filename if its missing
contentDisposition.FileName = (String.IsNullOrEmpty(contentDisposition.FileName) ? $"{Guid.NewGuid()}.data" : contentDisposition.FileName);
var size = contentDisposition.Size; // This is null right now!
}
}
}
这里是角度代码
$scope.$watch('files', function (files) {
$scope.formUpload = false;
console.log(files);
if (files != null) {
for (var i = 0; i < files.length; i++) {
$scope.errorMsg = null;
(function (file) {
file.size = 25;
upload(file);
})(files[i]);
}
}
});
function upload(file) {
file.upload = Upload.upload({
url: window.location.origin + "/api/mydocs/uploadfile?clientFolder=" + $scope.attachmentFolder + "&clientId=" + $scope.clientId + "&userId=" + $scope.currentUser.UserId,
method: 'POST',
headers: {},
fields: {},
file: file
});
问题:
如何让Angular包含内容处理标题中的文件大小?
谢谢!