package com.xkrs.qiniu.controller;

import com.xkrs.common.encapsulation.PromptMessageEnum;
import com.xkrs.qiniu.service.UploadImageService;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.web.bind.annotation.PostMapping;
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.util.Locale;

import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;

/**
 * @Author: XinYi Song
 * @Date: 2021/12/15 15:01
 */
@RestController
public class UploadFileController {

    @Resource
    private UploadImageService uploadImageService;

    /**
     * 将图片上传到七牛云
     * @param files
     * @return
     */
    @PostMapping("/qiNiuUploadFile")
    public String uploadFile(@RequestParam("files") MultipartFile files){
        Locale locale = LocaleContextHolder.getLocale();
        String uploadQiNiuImg = uploadImageService.uploadQiNiuImg(files);
        return outputEncapsulationObject(PromptMessageEnum.SUCCESS,uploadQiNiuImg,locale);
    }
}
