package com.fjhx.applet.controller;

import com.fjhx.applet.utils.OssUtil;
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.PostMapping;
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 java.io.IOException;

/**
 * 文件上传
 */
@RestController
@RequestMapping("/applet")
public class FileController {

    @PostMapping("/uploadFile")
    public R uploadFile(@RequestParam("file") MultipartFile file) {
        String path = OssUtil.getFileKey("web", file.getOriginalFilename());
        try {
            OssUtil.uploadFile(path, file.getInputStream());
        } catch (IOException e) {
            return R.fail("文件上传失败");
        }
        return R.success(OssUtil.getFilePath(path));
    }

}
