package com.github.pig.common.bean.feign;
import com.github.pig.common.bean.feign.fallback.FileServiceFallbackImpl;
import com.github.pig.common.vo.FileResult;
import feign.codec.Encoder;
import feign.form.spring.SpringFormEncoder;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.HttpMessageConverters;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.cloud.netflix.feign.support.SpringEncoder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.DeleteMapping;
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.multipart.MultipartFile;
@FeignClient(name = "pig-fileserver", fallback = FileServiceFallbackImpl.class,configuration = FileService.MultipartSupportConfig.class)
public interface FileService {
/**
* 文件上传
* @param file
* @return
*/
@PostMapping(value = "/", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
FileResult upload(@RequestPart("file") MultipartFile file);
/**
* 删除文件
* @param filePath
*/
@DeleteMapping
FileResult delete(@RequestParam("filePath") String filePath);
@Configuration
class MultipartSupportConfig {
@Autowired
private ObjectFactory<HttpMessageConverters> messageConverters;
@Bean
public Encoder feignFormEncoder() {
return new SpringFormEncoder(new SpringEncoder(messageConverters));
}
}
}
网友评论