package com.sv.oms.controller;

import com.sv.service.common.OSSClientUtil;
import com.ydd.framework.core.common.dto.ResponseDTO;
import com.ydd.oms.controller.OmsController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;

@RestController("upload")
@RequestMapping("/upload")
public class UploadController extends OmsController {


    @Resource
    private OSSClientUtil ossClientUtil;

    @RequestMapping("/image")
    public ResponseDTO uploadImg(@RequestParam("file") MultipartFile file) throws IOException {
        String imgUrl = ossClientUtil.uploadImg(file);
        return ResponseDTO.ok().addAttribute("img",imgUrl);
    }

    /**
     * 上传图片到阿里云
     * @return
     */
    @RequestMapping(value = "/uploadImg")
    public ResponseDTO uploadImage(MultipartFile file) throws IOException {
        String imgUrl = ossClientUtil.uploadImg(file);
        return ResponseDTO.ok(imgUrl);


    }

    /**
     * 上传视频到阿里云
     * @return
     */
    @RequestMapping(value = "/uploadVideo")
    public ResponseDTO uploadVideo(@RequestParam("video") MultipartFile multipartFile){
        String videoUrl = ossClientUtil.uploadVideo(multipartFile);
        return ResponseDTO.ok(videoUrl);
    }

}
