package com.fjs.scenic.upload;
import java.io.File;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

@Component
public class FileUtil {
	
	@Value("${img.path}")	
	private String path; 
	@Value("${img.addr}")	
	private String imgUrl; 
	
	public String  uploadFile(MultipartFile file) throws Exception{
		/*if(actice.equals("dev")){
			return imgUrl+"1563171679882277.jpg";
		}*/
		String fileName = file.getOriginalFilename();
		String suffixName = fileName.substring(fileName.lastIndexOf("."));
		// 文件上传后的路径
		fileName = ImgeNameUtils.genImageName() + suffixName;
		String uppath = path + fileName;
		File targetFile = new File(uppath);
		file.transferTo(targetFile);
		return imgUrl + fileName;
    }
	
}
