public static String upload(String imageUrls) throws Exception { String[] imageUrlArray = (","); MultiValueMap<String, Object> param = new LinkedMultiValueMap<>(); File[] files = new File[]; List<MultipartFile> multipartFileList = new ArrayList<>(); int index=0; for(String imageUrl : imageUrlArray) { //上传到cos files[index] = getFile(imageUrl); index ++; } String url = "你的服务端文件上传url"; List<File> list = null; String result = (url).header("Content-Type", ()).form("files", files).execute().body(); return result; }
public static File getFile(String url) throws Exception { //对本地文件命名 String fileName = (("."),()); File file = null; URL urlfile; InputStream inStream = null; OutputStream os = null; try { file = ("net_url", fileName); //下载 urlfile = new URL(url); inStream = (); os = new FileOutputStream(file); int bytesRead = 0; byte[] buffer = new byte[1024]; while ((bytesRead = (buffer, 0, 1024)) != -1) { (buffer, 0, bytesRead); } } catch (Exception e) { (); } finally { try { if (null != os) { (); } if (null != inStream) { (); } } catch (Exception e) { (); } } return file; }