我正在尝试使用上传音频文件的angularjs实现到我的应用程序 我收到了错误。
Maximum request length exceeded.
实际上我尝试使用最后一个程序员的另一个代码,我的上传图片代码中有效,但这个不起作用。
这是我的观看页面-audiofiles.html
<div class="page-content" style="padding:10%">
<div class="content-block">
<a href="#" class="button button-fill button-big" style="background-color:#2E7695;margin-bottom:30px;" ngf-select="uploadAudio(CaseAudio.AudioFile)" ng-model="CaseAudio.AudioFile" ngf-validate="{size: { max:'20mb', min:'10B'} }" ngf-pattern="'.mp3,.wmv'" accept=".mp3,.wmv" >Upload a audio file</a>
<!--<a href="#" class="button button-fill button-big" style="background-color:#2E7695;margin-bottom:30px;" ngf-select="uploadAudio(CaseAudio.AudioFile)" ng-model="CaseAudio.AudioFile" ngf-validate="{size: { max:'20mb', min:'10B'} }" >Upload a audio file</a> -->
<!--<button style="width:100%;background-color:#2E7695;" class="button button-big button-fill button-primary" ngf-select="uploadAudio(CaseAudio.file)" ngf-validate="{size: { max:'20mb', min:'10B'} }" ngf-pattern="'.mp3,.wmv'" accept=".mp3,.wmv"> Upload a audio file </button>-->
Audio preview: {{ CaseAudio.AudioFile.name }} <br />
<audio controls ngf-src="CaseAudio.AudioFile" style="width:100%"></audio>
</div>
的javascript
/* =========================================== */
/* 8.1 Audio Files */
/* =========================================== */
pagesModule.directive('pageAudiofiles', function () {
return {
restrict: 'E',
templateUrl: 'sam_app/components/pages/mea/casefiles/audio/page-audiofiles.html',
controller: pageAudiofiles,
controllerAs: 'pageAudiofilesCtrl',
}
});
function pageAudiofiles($scope) {
$SAM.InitObjects($scope);
$scope.CaseAudio = {
ngfBlobUrl: '',
AudioFile: '',
AudioFilePath: '',
}
$scope.caseAudios = [];
$scope.enableDelete = false;
$scope.uploadAudio = function(audioFile){
if(audioFile){
console.log("the audio is "+ audioFile);
/*if (!audioFile.$ngfBlobUrl) {
$SAM.notification.showNotification("Error", "error", "You can upload here only audio files.");
return;
}
*/
// print details
debugger
//save file in server
$SAM.services.uploadFile(audioFile, uploadProgress, uploadComplete, "POST", $SAM.services.WS.UploadCaseFileImage);
$scope.caseAudios.push({ ngfBlobUrl: audioFile.$ngfBlobUrl, AudioFilePath: '', uploadedDate: $SAM.miscUtils.ConvertCSdateToJSdate(new Date().getTime()), progress: 0, error: '' });
}
}
function uploadProgress(evt, file) {
$scope.$apply(function () {
//$scope.CaseAudio = $.grep($scope.caseAudios, function (v) { return v.ngfBlobUrl === file.$ngfBlobUrl; })[0];
//show the progress bar on the correct block image
debugger
console.log("caseAudio: " + $scope.CaseAudio);
var str = JSON.stringify($scope.CaseAudio);
console.log("CaseAudio object: " + str);
if (evt.lengthComputable) {
$scope.CaseAudio.progress = Math.round(evt.loaded * 100 / evt.total);
} else {
$scope.CaseAudio.error = 'Upload Error ' + 'unable to compute';
}
})
}
function uploadComplete(evt, file) {
$scope.$apply(function () {
//get the correct block case image object
$scope.CaseAudio = $.grep($scope.caseAudios, function (v) { return v.ngfBlobUrl === file.$ngfBlobUrl; })[0];
//set the virtual path
var data = JSON.parse(evt.target.response);
if (data.Status == $SAM.ResponseStatus.ErrorMessage) {
$scope.CaseAudio.error = data.Message;
}
else {
//hide the progress bar
$scope.CaseAudio.progress = false;
$scope.CaseAudio.picFilePath = data.Message;
}
})
}
}
uploadFile函数
$SAM.services.uploadFile = function (file, uploadProgress_callback, uploadComplete_callback, method, url) {
var fd = new FormData();
fd.append("uploadedFile", file);
fd.append("caseID", $SAM.MEACase.caseID);
var xhr = new XMLHttpRequest()
xhr.upload.addEventListener("progress", function (evt) {
uploadProgress_callback(evt, file);
}, false);
xhr.addEventListener("load", function (evt) {
var data = JSON.parse(evt.target.response);
if (data.EXEPTION) {
$SAM.services.scope.$apply(function () {
$SAM.miscUtils.showLoadingSpinner = false;
$SAM.exception.constructor(data.EXEPTION);
$SAM.exception.PopupException = 'in';
});
}
else {
uploadComplete_callback(evt, file);
}
}, false);
xhr.addEventListener("error", function (evt) {
$SAM.services.scope.$apply(function () {
$SAM.miscUtils.showLoadingSpinner = false;
var data = JSON.parse(evt.target.response);
$SAM.exception.constructor(data.EXEPTION);
$SAM.exception.PopupException = 'in';
});
}, false);
xhr.open(method, url);
xhr.send(fd);
}
$SAM.services.log = $log;
$SAM.services.q = $q;
$SAM.services.scope = $scope;
$SAM.services.timeout = $timeout;
}
我们构建的webservice适用于图像
[WebMethod(EnableSession = true)]
[Secure(UserPermissions.Standart)]
public void UploadCaseFileImage()
{
// string n = "781";
try
{
SAMFile samfile = new SAMFile(HttpContext.Current.Request.Files[0], BelongEntitys.CaseImages, HttpContext.Current.Request["caseID"]);
//SAMFile samfile = new SAMFile(HttpContext.Current.Request.Files[0], BelongEntitys.CaseImages, n);
if (samfile.UserID == ManagersGateway.User.PKID)
{
string virtualPath = CaseModule.UploadImageFileToCase(samfile);
Context.Response.Write(HTTPResponseBuilder.Build(HTTPResponseStatus.OK, virtualPath));
}
}
catch (Exception e)
{
if (e is CustomException) ExceptionMessage.ThrowExeptionToResponse(e as CustomException, true);
else ExceptionMessage.ThrowExeptionToResponse(e.Message, Resources.ServerError, ErrorCode.CD1032, true);
}
}