package org.springblade.modules.resource.controller;

import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import org.springblade.core.oss.MinioTemplate;
import org.springblade.core.oss.model.BladeFile;
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;

@RestController
@AllArgsConstructor
@RequestMapping("blade-resource/file")
public class FileController {

	private MinioTemplate minioTemplate;

	@SneakyThrows
	@PostMapping("/putFile")
	public R putFile(@RequestParam MultipartFile file){
		BladeFile bladeFile = minioTemplate.putFile("bladex", file.getOriginalFilename(), file.getInputStream());
		String link = bladeFile.getLink();
		return R.data(link);
	}
}
