package com.supServer.project.controller;

import com.supServer.common.utils.file.AliOssUtil;
import com.supServer.framework.web.domain.AjaxResult;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.text.ParseException;

/**
 * @description：
 * @Author:
 * @Date: 2022/4/13 12:43
 */
@RequestMapping("/file")
@RestController
public class FileController {

    /**
     * 上传文件
     * @param file
     * @return
     */
    @PostMapping("/uploadFile")
    public AjaxResult uploadFile(@RequestParam("file") MultipartFile file) throws ParseException, IOException {
        if (ObjectUtils.isEmpty(file) || ObjectUtils.isEmpty(file.getOriginalFilename())){
            return AjaxResult.error("文件流或文件名称为空");
        }
        //上传
        String s = AliOssUtil.uploadFile(file);
        AjaxResult ajaxResult = AjaxResult.success();
        ajaxResult.put("url",s);
        ajaxResult.put("fileName",file.getOriginalFilename());
        return ajaxResult;
    }

}
