package cn.hhj.controller; import cn.hhj.util.RemoteUploadUtil; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.auth.AuthScope; import org.apache.http.auth.Credentials; import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.client.CredentialsProvider; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.protocol.HttpClientContext; import org.apache.http.entity.ContentType; import org.apache.http.entity.mime.MultipartEntityBuilder; import org.apache.http.impl.client.BasicCredentialsProvider; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.multipart.MultipartFile; import java.nio.charset.Charset; @Controller @RequestMapping("/consumer") public class ConsumerUploadController { // 设置要进行远程上传微服务调用的代理地址 public static final String UPLOAD_URL = "http://gateway-9501.com:9501/zuul/QingSe/upload-proxy/upload"; @GetMapping("uploadPre") public String uploadPre() { return "upload" ; } @ResponseBody @PostMapping("upload") public String upload(String name, MultipartFile photo)throws Exception{ System.err.println("【"+name+"正在执行远程文件上传】"); return RemoteUploadUtil.remoteupload(photo,UPLOAD_URL); } }