|
|
@ -16,7 +16,9 @@ import org.apache.http.HttpResponse;
|
|
|
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
|
import org.apache.http.client.methods.HttpGet;
|
|
|
|
import org.apache.http.client.methods.HttpGet;
|
|
|
|
import org.apache.http.client.methods.HttpPost;
|
|
|
|
import org.apache.http.client.methods.HttpPost;
|
|
|
|
|
|
|
|
import org.apache.http.entity.ContentType;
|
|
|
|
import org.apache.http.entity.StringEntity;
|
|
|
|
import org.apache.http.entity.StringEntity;
|
|
|
|
|
|
|
|
import org.apache.http.entity.mime.HttpMultipartMode;
|
|
|
|
import org.apache.http.entity.mime.MultipartEntityBuilder;
|
|
|
|
import org.apache.http.entity.mime.MultipartEntityBuilder;
|
|
|
|
import org.apache.http.entity.mime.content.ByteArrayBody;
|
|
|
|
import org.apache.http.entity.mime.content.ByteArrayBody;
|
|
|
|
import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
|
import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
@ -132,14 +134,39 @@ public class JupyterhubController {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// public static void uploadFile(String url, MultipartFile file, String caseName) throws IOException {
|
|
|
|
|
|
|
|
// try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
|
|
|
|
|
|
|
|
// HttpPost uploadFile = new HttpPost(url);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // Build the multipart entity
|
|
|
|
|
|
|
|
// MultipartEntityBuilder builder = MultipartEntityBuilder.create();
|
|
|
|
|
|
|
|
// builder.addPart("file", new ByteArrayBody(file.getBytes(), file.getOriginalFilename())); // Use ByteArrayBody for MultipartFile
|
|
|
|
|
|
|
|
// builder.addTextBody("caseName", caseName);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// HttpEntity entity = builder.build();
|
|
|
|
|
|
|
|
// uploadFile.setEntity(entity);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // Execute the request
|
|
|
|
|
|
|
|
// try (CloseableHttpResponse response = httpClient.execute(uploadFile)) {
|
|
|
|
|
|
|
|
// HttpEntity responseEntity = response.getEntity();
|
|
|
|
|
|
|
|
// String responseString = EntityUtils.toString(responseEntity, "UTF-8");
|
|
|
|
|
|
|
|
// System.out.println("Response: " + responseString);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
public static void uploadFile(String url, MultipartFile file, String caseName) throws IOException {
|
|
|
|
public static void uploadFile(String url, MultipartFile file, String caseName) throws IOException {
|
|
|
|
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
|
|
|
|
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
|
|
|
|
HttpPost uploadFile = new HttpPost(url);
|
|
|
|
HttpPost uploadFile = new HttpPost(url);
|
|
|
|
|
|
|
|
|
|
|
|
// Build the multipart entity
|
|
|
|
// Build the multipart entity
|
|
|
|
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
|
|
|
|
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
|
|
|
|
builder.addPart("file", new ByteArrayBody(file.getBytes(), file.getOriginalFilename())); // Use ByteArrayBody for MultipartFile
|
|
|
|
|
|
|
|
builder.addTextBody("caseName", caseName);
|
|
|
|
// Use ByteArrayBody with proper encoding for the file name
|
|
|
|
|
|
|
|
ByteArrayBody byteArrayBody = new ByteArrayBody(file.getBytes(), file.getOriginalFilename());
|
|
|
|
|
|
|
|
builder.addPart("file", byteArrayBody);
|
|
|
|
|
|
|
|
builder.addTextBody("caseName", caseName, ContentType.TEXT_PLAIN.withCharset("UTF-8"));
|
|
|
|
|
|
|
|
builder.setMode(HttpMultipartMode.RFC6532);//解决文件名乱码问题
|
|
|
|
|
|
|
|
|
|
|
|
HttpEntity entity = builder.build();
|
|
|
|
HttpEntity entity = builder.build();
|
|
|
|
uploadFile.setEntity(entity);
|
|
|
|
uploadFile.setEntity(entity);
|
|
|
@ -147,7 +174,8 @@ public class JupyterhubController {
|
|
|
|
// Execute the request
|
|
|
|
// Execute the request
|
|
|
|
try (CloseableHttpResponse response = httpClient.execute(uploadFile)) {
|
|
|
|
try (CloseableHttpResponse response = httpClient.execute(uploadFile)) {
|
|
|
|
HttpEntity responseEntity = response.getEntity();
|
|
|
|
HttpEntity responseEntity = response.getEntity();
|
|
|
|
String responseString = EntityUtils.toString(responseEntity);
|
|
|
|
// Convert response entity to String with UTF-8 encoding
|
|
|
|
|
|
|
|
String responseString = EntityUtils.toString(responseEntity, "UTF-8");
|
|
|
|
System.out.println("Response: " + responseString);
|
|
|
|
System.out.println("Response: " + responseString);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|