package com.icloud.server.file;

import com.icloud.server.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;

import java.io.IOException;

@Api( tags = {"文件上传" }, value = "API",hidden = true )
@RestController
@RequestMapping("file")
@CrossOrigin
public class CosContoller {
//    @PostMapping("/upload")
//    @ApiOperation("上传文件")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "file", value = "文件附件", required = true, dataTypeClass = MultipartFile.class),
//            @ApiImplicitParam(name = "path", value = "文件路径", example = "yudaoyuanma.png", dataTypeClass = String.class)
//    })
//    public CommonResult<String> uploadFile(@RequestParam("file") MultipartFile file,
//                                           @RequestParam("path") String path) throws IOException {
//        return success(fileService.createFile(path, IoUtil.readBytes(file.getInputStream())));
//    }
    @Autowired
    private AliOss oss;

    @PostMapping("/upload")
    @ApiOperation("上传文件")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file", value = "图片", required = true, dataTypeClass = MultipartFile.class)
    })
    public JsonResult uploadFile(@RequestParam("file") MultipartFile file) throws IOException {
        return new JsonResult( oss.up(file));
    }


    @PostMapping("/upload_plus")
    @ApiOperation("上传文件")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file", value = "图片", required = true, dataTypeClass = MultipartFile.class),
            @ApiImplicitParam(name = "uid", value = "用户id", required = true, dataTypeClass = String.class)
    })
    public JsonResult uploadFile1(@RequestParam("file") MultipartFile file,@RequestParam String uid) throws IOException {
        return new JsonResult( oss.up(file));
    }
}
