发表于: 2017-04-28 21:24:06

1 964


今天完成的事情:今天完成了任务9.
明天计划的事情:开始写任务10.
遇到的问题:今天下午弄了一下午的进度条 还是弄不起来,只好做了个假的。在网上查到要用angular的

eventHandlers和uploadEventHandlers百度了资料 查看了官方文档写的很简略。。。

 //         eventHandlers: {

    //     readystatechange: function(event) {

    //                     if(event.currentTarget.readyState === 4) {

    //                         console.log("readyState=4: Server has finished extra work!");

    //                     }

    //                 }

    // },

    //         uploadEventHandlers: {

    //     progress: function(e) {

    //          if (e.lengthComputable) {

    //             progress = Math.round(e.loaded * 100 / e.total);

    //             console.log("progress: " + progress + "%");

    //             if (e.loaded = e.total) {

    //               console.log("File upload finished!");

    //               console.log("Server will perform extra work now...");

    //             }

    //         }

    //     }

    // }

试了一下还是没啥用。


收获:

写了一个发送图片的factory。

.factory('fileUpload', ['$http', function ($http) {

    return {uploadFileToUrl :function(file, uploadUrl){

         var fd = new FormData();

         fd.append('file', file);

     return     $http.post(uploadUrl, fd, {

            transformRequest: angular.identity,

            headers: {'Content-Type': undefined}

写了一个filter 去计算图片的大小。

//计算图片大小

myApp.filter('imgSize',function() {

return function(input){

var size="";

if (input>=1024*1024) {

size = (Math.round(input* 100 / (1024 * 1024)) / 100).toString() + 'MB';

}else{

size = (Math.round(input * 100 / 1024) / 100).toString() + 'KB';

}

return size;

}

});




返回列表 返回列表
评论

    分享到