package com.starry.admin.common.oss.controller;

import com.starry.admin.common.oss.service.IOssFileService;
import com.starry.common.result.R;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
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;

/**
 * @author admin cos存储前端控制器
 * @since 2022/11/13 17:51
 */
@Slf4j
@RestController
@RequestMapping("/cos")
public class CosController {

    @Resource
    IOssFileService ossFileService;

    @ApiOperation(value = "照片上传")
    @PostMapping("/upload/image")
    public R uploadImage(MultipartFile file) throws Exception {
        if (!file.isEmpty()) {
            String house = ossFileService.upload(file.getInputStream(), "house", file.getOriginalFilename());
            return R.ok(house);
        }
        return R.error("上传照片异常，请联系管理员");
    }
}
