package org.springblade.resource.feign;

import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import org.springblade.core.oss.model.BladeFile;
import org.springblade.core.tool.api.R;
import org.springblade.resource.builder.oss.OssBuilder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;

/**
 * Created By lidexi in 2021/4/28
 **/
@RestController
@AllArgsConstructor
public class OssEndpointClient implements IOssEndpointClient {

	/**
	 * 对象存储构建类
	 */
	private final OssBuilder ossBuilder;

	@Override
	@SneakyThrows
	@PostMapping(API_PREFIX+"/put-file")
	public R<BladeFile> putFile(@RequestPart("file") MultipartFile file) {
		BladeFile bladeFile = ossBuilder.template().putFile(file.getOriginalFilename(), file.getInputStream());
		return R.data(bladeFile);

	}
}
