package org.jeecg.modules.fileupload.controller;

import org.jeecg.modules.fileupload.service.IUploadService;
import org.springframework.beans.factory.annotation.Autowired;
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 javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author jeecg-boot
 */
@RestController
@RequestMapping("upload")
public class UploadController {
    @Autowired
    private IUploadService uploadService;

    @PostMapping(value = "image", consumes = "multipart/form-data;charset=utf-8")
    public Map<String, Object> uploadImage(@RequestParam("multipartFile") MultipartFile multipartFile, String type, HttpServletRequest request) {
        return uploadService.imageUpload(multipartFile, request, type);
    }

    @PostMapping(value = "video", consumes = "multipart/form-data;charset=utf-8")
    public Map<String, Object> uploadVideo(@RequestParam("multipartFile") MultipartFile multipartFile, String type, HttpServletRequest request) {
        return uploadService.videoUpload(multipartFile, request, type);
    }
}
