package com.huiju.foyo.service.impl;

import com.huiju.foyo.service.ImageServiceI;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.util.Date;

/**
 * @author weichaochao
 * @Title: ImageServiceimpl
 * @Description: 获取图片地址实现类
 * @date 2018/11/5
 */
@Service("ImageService")
public class ImageServiceimpl implements ImageServiceI {
    @Value("${assets.images}")
    String imagePath;
    
    @Override
    public String getImageUrl(MultipartFile uploadFile) throws IOException {
        //保存的文件名
        String imgName = System.currentTimeMillis() + ".png";
        //保存路径
        String path = imagePath + imgName;
        String rebackPath = "/uploadimage/" + imgName;
        //生成保存文件
        File troUploadFile = new File(path);
        //将上传文件保存到路径
        try {
            uploadFile.transferTo(troUploadFile);
        } catch (IOException e) {
            e.printStackTrace();
        }
        
        return rebackPath;
    }

//  @Override
//  public String getVideoUrl(MultipartFile uploadFile) throws IOException {
//    //保存的文件名
//    String imgName = System.currentTimeMillis() + ".mp4";
//    //保存路径
//    String path = imagePath + imgName;
//    String rebackPath = "/uploadimage/" + imgName;
//    //生成保存文件
//    File troUploadFile = new File(path);
//    //将上传文件保存到路径
//    try {
//      uploadFile.transferTo(troUploadFile);
//    } catch (IOException e) {
//      e.printStackTrace();
//    }
//
//    return rebackPath;
//  }
}
