图片分页
This commit is contained in:
6
pom.xml
6
pom.xml
@ -79,6 +79,12 @@
|
|||||||
<version>7.2.5</version>
|
<version>7.2.5</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.coobird</groupId>
|
||||||
|
<artifactId>thumbnailator</artifactId>
|
||||||
|
<version>0.4.20</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|||||||
@ -1,99 +0,0 @@
|
|||||||
/*
|
|
||||||
package com.example.sso.test;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
import com.alibaba.fastjson.JSONArray;
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.example.sso.dao.C;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.http.HttpEntity;
|
|
||||||
import org.apache.http.HttpResponse;
|
|
||||||
import org.apache.http.client.methods.HttpPost;
|
|
||||||
import org.apache.http.entity.ContentType;
|
|
||||||
import org.apache.http.entity.mime.MultipartEntityBuilder;
|
|
||||||
import org.apache.http.entity.mime.content.FileBody;
|
|
||||||
import org.apache.http.entity.mime.content.StringBody;
|
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
|
||||||
import org.apache.http.impl.client.HttpClients;
|
|
||||||
import org.apache.http.util.EntityUtils;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLConnection;
|
|
||||||
import java.nio.charset.Charset;
|
|
||||||
@Slf4j
|
|
||||||
@RestController
|
|
||||||
public class CeShi {
|
|
||||||
@PostMapping("/test")
|
|
||||||
public JSONObject main1(@RequestBody C c) throws IOException {
|
|
||||||
//String fileUrl = "https://fz-zion-static.functorz.com/202403290302/2580e8a228755ecb953645bcf20700ac/project/2000000000282320/images/HDzOpA6kQuD994hibpYtyA==.jpg";
|
|
||||||
String saveDir = "/home/appdown"; // 本地文件夹路径
|
|
||||||
String fileName ="";
|
|
||||||
|
|
||||||
try {
|
|
||||||
URL url = new URL(c.getFileUrl());
|
|
||||||
URLConnection conn = url.openConnection();
|
|
||||||
InputStream inputStream = conn.getInputStream();
|
|
||||||
|
|
||||||
fileName = c.getFileUrl().substring(c.getFileUrl().lastIndexOf("/") + 1);
|
|
||||||
String saveFilePath = saveDir + File.separator + fileName;
|
|
||||||
|
|
||||||
FileOutputStream outputStream = new FileOutputStream(saveFilePath);
|
|
||||||
|
|
||||||
int bytesRead;
|
|
||||||
byte[] buffer = new byte[4096];
|
|
||||||
while ((bytesRead = inputStream.read(buffer)) != -1) {
|
|
||||||
outputStream.write(buffer, 0, bytesRead);
|
|
||||||
}
|
|
||||||
|
|
||||||
outputStream.close();
|
|
||||||
inputStream.close();
|
|
||||||
|
|
||||||
System.out.println("文件下载完成");
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
String key = key(c.getToken(), fileName);
|
|
||||||
System.out.println(key);
|
|
||||||
JSONArray jsonArray = new JSONArray();
|
|
||||||
jsonArray.add(key);
|
|
||||||
|
|
||||||
JSONObject jsonObject = new JSONObject();
|
|
||||||
jsonObject.put("key",jsonArray);
|
|
||||||
return jsonObject;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String key( String token,String top) throws IOException {
|
|
||||||
String url = "https://www.jiyuankeshang.com/_/file/upload/put_file";
|
|
||||||
File file = new File("/home" + File.separator + "appdown" + File.separator + top);
|
|
||||||
String PATH = "D:\\11.txt";
|
|
||||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
|
||||||
HttpPost httpPost = new HttpPost(url);
|
|
||||||
// httpPost.setHeader("Content-Type", "form-data");
|
|
||||||
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
|
|
||||||
builder.addPart("token", new StringBody(token, ContentType.create("text/plain", Charset.forName("UTF-8"))));
|
|
||||||
builder.addPart("file", new FileBody(file, ContentType.create("jpg"), file.getName()));
|
|
||||||
HttpEntity entity = builder.build();
|
|
||||||
|
|
||||||
httpPost.setEntity(entity);
|
|
||||||
HttpResponse response = httpClient.execute(httpPost);
|
|
||||||
int statusCode = response.getStatusLine().getStatusCode();
|
|
||||||
|
|
||||||
HttpEntity entity1 = response.getEntity();
|
|
||||||
String string = EntityUtils.toString(entity1);
|
|
||||||
JSONObject jsonObject = JSON.parseObject(string);
|
|
||||||
String key = jsonObject.getString("key");
|
|
||||||
|
|
||||||
return key;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
Reference in New Issue
Block a user