package com.huiju.foyo.controller;


import com.huiju.foyo.common.ResponseBean;
import com.huiju.foyo.service.ImageServiceI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;

/**
 * @author weichaochao
 * @Title: ImageController
 * @Description: 图片上传以及获取url
 * @date 2018/10/31
 */
@RestController
@RequestMapping("/")
public class ImageController {

    @Autowired
    private ImageServiceI imageService;

    
    @PostMapping(value = "/admin/uploadimage", consumes = "multipart/*", headers = "content-type=multipart/form-data")
    public ResponseBean uploadImgAndGetUrl(MultipartFile[] uploadFiles) throws Exception {
        ResponseBean responseBean = new ResponseBean();
        List<String> urls = new ArrayList<String>();
        for (MultipartFile uploadFile : uploadFiles){
            String url = imageService.getImageUrl(uploadFile);
            urls.add(url);
        }
        responseBean.addSuccess(urls);
        return responseBean;
    }


}
