package org.fouram.core.base.controller;

import org.fouram.core.base.model.PageData;
import org.fouram.core.util.AppUtil;
import org.fouram.core.util.FileUpload;
import org.fouram.core.util.LoggerUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

/**
 * 文件上传
 * 
 * @author liup
 * 
 */
@Controller
@RequestMapping(value = "/upload")
public class UploadController extends BaseController {
	
	/**
	 * 上传文件
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/uploadFile", produces = "application/json;charset=utf-8")
	@ResponseBody
	public PageData uploadFile(@RequestParam(value = "file", required = false) MultipartFile file) {
		try {
			LoggerUtil.info(file == null);
			PageData pdd = new PageData();
			pdd.put("fileUrl", FileUpload.fileUpload(file));
			LoggerUtil.info(pdd);
			return AppUtil.success(pdd, "上传成功");
		} catch (Exception e) {
			LoggerUtil.error(e);
			return AppUtil.error("上传失败");
		}
	}
}
