(function (exports) {
	var fileAPI = {
		//文件流上传图片
		uploadImg: function (data) {
			return httpRequest.httpPostContent("/dfs/api/v1.0/fastDfs/upload?creator="+data.creator+"&objectId="+data.objectId,{data: data.files, processData : false, contentType : false})
		},
		getBase64Image: //将图片压缩转成base64   
			function (imgSrc,width) {
				return new Promise(function (resolve, reject) {
					var canvas = document.createElement("canvas");
					var img = new Image;
					img.src = imgSrc;
		
					if(width){
					 img.width = width;
					 img.height = width;
					}
					var ctx = canvas.getContext("2d");
					img.onload = function () {
						canvas.width = img.width; /*设置新的图片的宽度*/
						canvas.height = img.height; /*设置新的图片的长度*/
						ctx.drawImage(img, 0, 0, img.width, img.height); /*绘图*/
						var dataURL = canvas.toDataURL("image/png", 0.8);
						resolve(dataURL.replace("data:image/png;base64,", ""));
					}
				})
			},
		zipImg:function(src,isSmall){
			return new Promise(function(resolve,redirect){
				var aImg = src.split("/");
				var imgName = aImg[aImg.length - 1];
				plus.zip.compressImage({
					src: src,
					dst: aImg+imgName,
					quality: 20,
					overwrite: true,
					width:'50%'
				}, function(succ) {
					var url = succ.target;
					var size = succ.size;
					var width = succ.width;
					var height = succ.height;
					resolve(succ)
				}, function(err) {
					console.error("压缩失败:" + err.message);
					redirect(err)
					if(err.message == "文件不存在") {
						mui.toast(err.message);
						plus.nativeUI.closeWaiting();
						plus.webview.currentWebview().reload();
					}
				});
			})
			
		}


	}




	exports.fileAPI = fileAPI;
})(window)