|
|
@ -1,39 +1,102 @@
|
|
|
|
package com.connor.uploadfile;
|
|
|
|
package com.connor.uploadfile;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.checkerframework.common.returnsreceiver.qual.This;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
|
|
|
|
|
|
import io.minio.GetPresignedObjectUrlArgs;
|
|
|
|
import io.minio.GetPresignedObjectUrlArgs;
|
|
|
|
import io.minio.MinioClient;
|
|
|
|
import io.minio.MinioClient;
|
|
|
|
import io.minio.ObjectWriteResponse;
|
|
|
|
|
|
|
|
import io.minio.PutObjectArgs;
|
|
|
|
|
|
|
|
import io.minio.UploadObjectArgs;
|
|
|
|
import io.minio.UploadObjectArgs;
|
|
|
|
import io.minio.http.Method;
|
|
|
|
import io.minio.http.Method;
|
|
|
|
|
|
|
|
import okhttp3.MediaType;
|
|
|
|
|
|
|
|
import okhttp3.OkHttpClient;
|
|
|
|
|
|
|
|
import okhttp3.Request;
|
|
|
|
|
|
|
|
import okhttp3.RequestBody;
|
|
|
|
|
|
|
|
import okhttp3.Response;
|
|
|
|
|
|
|
|
|
|
|
|
public class UploadFile {
|
|
|
|
public class UploadFile {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
public static void main(String args[]) {
|
|
|
|
public static void main(String args[]) {
|
|
|
|
String filePath = args[0];//"D:\\1.txt";//
|
|
|
|
String filePath = args[0];//"D:\\1.txt";//
|
|
|
|
// InputStream in = null;
|
|
|
|
// InputStream in = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
File file = new File(filePath);
|
|
|
|
if(filePath.equals("FS")) {
|
|
|
|
String sendFileToMinio = sendFileToMinio(file, "SapBomLog/" + file.getName());
|
|
|
|
// System.out.println("args[1]:" + args[1]);
|
|
|
|
System.out.println(sendFileToMinio);
|
|
|
|
/*OkHttpClient client = new OkHttpClient();
|
|
|
|
|
|
|
|
MediaType mediaType = MediaType.parse("application/json");
|
|
|
|
|
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
|
|
|
|
RequestBody body = RequestBody.create(mediaType, args[1]);
|
|
|
|
|
|
|
|
Request request =
|
|
|
|
|
|
|
|
new Request.Builder()
|
|
|
|
|
|
|
|
.url("http://10.128.10.170/api/feishu/Message/sendMessages")
|
|
|
|
|
|
|
|
.method("POST", body)
|
|
|
|
|
|
|
|
.addHeader("Content-Type", "application/json")
|
|
|
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
Response response = client.newCall(request).execute();
|
|
|
|
|
|
|
|
System.out.println(response.body().string());*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//TODO lidy20240828新接口 先获取token,再组织数据
|
|
|
|
|
|
|
|
OkHttpClient client = new OkHttpClient();
|
|
|
|
|
|
|
|
RequestBody body = RequestBody.create(null, new byte[0]);
|
|
|
|
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
|
|
|
|
.url("https://pub.chintelec.com/api/getToken?appId=zt_plm&appSecret=RA5KfdZtj37zpVsmgKeSxWncEIT8npVf")
|
|
|
|
|
|
|
|
.post(body)
|
|
|
|
|
|
|
|
// .addHeader("User-Agent", "PostmanRuntime/7.15.2")
|
|
|
|
|
|
|
|
// .addHeader("Accept", "*/*")
|
|
|
|
|
|
|
|
// .addHeader("Cache-Control", "no-cache")
|
|
|
|
|
|
|
|
// .addHeader("Postman-Token", "a9295d9a-e069-4098-bc7b-af6ad2f37f8a,48f24111-1460-4588-8c1d-ad4f6d809d94")
|
|
|
|
|
|
|
|
// .addHeader("Host", "pub.chintelec.com")
|
|
|
|
|
|
|
|
// .addHeader("Accept-Encoding", "gzip, deflate")
|
|
|
|
|
|
|
|
// .addHeader("Content-Length", "")
|
|
|
|
|
|
|
|
// .addHeader("Connection", "keep-alive")
|
|
|
|
|
|
|
|
// .addHeader("cache-control", "no-cache")
|
|
|
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
Response response = client.newCall(request).execute();
|
|
|
|
|
|
|
|
String res = response.body().string();
|
|
|
|
|
|
|
|
JSONObject jsonObject = new JSONObject(res);
|
|
|
|
|
|
|
|
// System.out.println(res);
|
|
|
|
|
|
|
|
if(!jsonObject.getBoolean("success")) {
|
|
|
|
|
|
|
|
System.out.println(res);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String token = jsonObject.getString("data");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
client = new OkHttpClient();
|
|
|
|
|
|
|
|
MediaType mediaType = MediaType.parse("application/json");
|
|
|
|
|
|
|
|
String json = args[1].replaceAll(",\"admin\"", "").replaceAll("\"admin\",", "").replaceAll("\"admin\"", "");
|
|
|
|
|
|
|
|
body = RequestBody.create(mediaType, json);
|
|
|
|
|
|
|
|
request = new Request.Builder()
|
|
|
|
|
|
|
|
.url("https://pub.chintelec.com/api/open/Feishu/sendMessages")
|
|
|
|
|
|
|
|
.post(body)
|
|
|
|
|
|
|
|
.addHeader("Authorization", token)
|
|
|
|
|
|
|
|
.addHeader("Content-Type", "application/json")
|
|
|
|
|
|
|
|
// .addHeader("User-Agent", "PostmanRuntime/7.15.2")
|
|
|
|
|
|
|
|
// .addHeader("Accept", "*/*")
|
|
|
|
|
|
|
|
// .addHeader("Cache-Control", "no-cache")
|
|
|
|
|
|
|
|
// .addHeader("Postman-Token", "26eae4d3-be83-4345-b5a2-b85c2f21c8a4,4183d845-8d4d-4e9f-9320-ec183098656e")
|
|
|
|
|
|
|
|
// .addHeader("Host", "pub.chintelec.com")
|
|
|
|
|
|
|
|
// .addHeader("Accept-Encoding", "gzip, deflate")
|
|
|
|
|
|
|
|
// .addHeader("Content-Length", "142")
|
|
|
|
|
|
|
|
// .addHeader("Connection", "keep-alive")
|
|
|
|
|
|
|
|
// .addHeader("cache-control", "no-cache")
|
|
|
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
response = client.newCall(request).execute();
|
|
|
|
|
|
|
|
System.out.println(response.body().string());
|
|
|
|
|
|
|
|
}else {
|
|
|
|
|
|
|
|
File file = new File(filePath);
|
|
|
|
|
|
|
|
String sendFileToMinio = sendFileToMinio(file, "SapBomLog/" + file.getName());
|
|
|
|
|
|
|
|
System.out.println(sendFileToMinio);
|
|
|
|
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
// Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
System.exit(0);
|
|
|
|
System.exit(0);
|
|
|
|
// System.out.println("11111");
|
|
|
|
// System.out.println("11111");
|
|
|
|
// return;
|
|
|
|
// return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public static String sendFileToMinio(File file, String minioObj) throws Exception {
|
|
|
|
private static String sendFileToMinio(File file, String minioObj) throws Exception {
|
|
|
|
|
|
|
|
|
|
|
|
// InputStream in = new FileInputStream(file);
|
|
|
|
// InputStream in = new FileInputStream(file);
|
|
|
|
MinioClient client = MinioClient.builder().endpoint("http://10.128.11.20:9000")
|
|
|
|
MinioClient client = MinioClient.builder().endpoint("http://10.128.11.20:9000")
|
|
|
|