|
我要实现拍照并且上传功能。
- // 上传图片到服务器
- var uploadPicture = function ( imageURI ){
- var deferred = when.defer();
- var options = new FileUploadOptions();
- options.fileKey = "file";
- options.fileName = imageURI.substr(imageURI.lastIndexOf('/')+1);
- options.mimeType = "image/jpeg";
- var ft = new FileTransfer();
- // 上传回调
- $ionicLoading.show({
- template: "已经上传:0%"
- });
- ft.onprogress = function ( progressEvent ){
- $timeout(function () {
- var downloadProgress = (progressEvent.loaded / progressEvent.total) * 100;
- $ionicLoading.show({
- template: "已经上传:" + Math.floor(downloadProgress) + "%"
- });
- if (downloadProgress > 99) {
- $ionicLoading.hide();
- }
- })
- };
- ft.upload( imageURI, encodeURI('http://XXX.XXX.XXX.XXX:XX/OaJsonServiceTest/PhotoAndUploadService/UploadPhoto.ashx')
- , function(data){
- alert("成功");
- deferred.resolve( imageURI );
- } , function(err){
- alert("失败");
- }, options);
- return deferred.promise;
- };
复制代码 以上是上传的方法。
服务端我也不会写,就网上down了一个大神"神色自若"的代码,如下:
- public void ProcessRequest (HttpContext context) {
- context.Response.ContentType = "text/plain";
- context.Response.Charset = "utf-8";
- HttpPostedFile file = context.Request.Files["fileAddPic"];
- // fileAddPic为app端FileUploadOptions传入参数,此点非常重要
- string fileName = "123.jpeg";//file.FileName;
- string folder = "~/upLoad";
- string uploadPath = HttpContext.Current.Server.MapPath(folder + "\\");
- if (file != null)
- {
- file.SaveAs(uploadPath + fileName);
- context.Response.Write("上传OK");
- }
- else
- {
- context.Response.Write("上传失败");
- }
-
- }
复制代码 为什么每次上传进度快完成时就失败啊?求大神解答
|
|