```java
package com.utils;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Base64;
public class UploadFile {
private static final String boundary = "----WebKitFormBoundary0jkH3KeWg3pxZxJ5";
public static String uploadFn(String base64Code,String port) throws Exception {
URL url = new URL(port);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
httpURLConnection.setDoOutput(true);
DataOutputStream outputStream = new DataOutputStream(httpURLConnection.getOutputStream());
String fieldName = System.currentTimeMillis()+".png";
setFileByBase64(outputStream, base64Code, fieldName);
setParam(outputStream, "filename", fieldName);
setParam(outputStream, "action", "uploadfile");
setParam(outputStream, "calltoken", "3979189c96de598a7c2e10433bb1885a");
setParam(outputStream, "jsontype", "");
setParam(outputStream, "userid", "23af16b1-1ca3-4054-bc20-71d425eb48da");
setParam(outputStream, "customercode", "2020");
outputStream.writeBytes("\r\n--" + boundary + "--\r\n");
outputStream.flush();
outputStream.close();
int responseCode = httpURLConnection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
BufferedReader in = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
String inputLine;
StringBuilder content = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
content.append(inputLine);
}
in.close();
return content.toString();
} else {
return "{}";
}
}
public static void setParam(DataOutputStream outputStream, String key, String value) throws Exception {
outputStream.writeBytes("\r\n--" + boundary + "\r\n");
outputStream.writeBytes("Content-Disposition: form-data; name=\"" + key + "\"\r\n\r\n");
outputStream.writeBytes(value);
}
public void setFile(DataOutputStream outputStream, String path) throws Exception {
File file = new File(path);
FileInputStream fis = new FileInputStream(file);
byte[] fileBytes = new byte[(int) file.length()];
fis.read(fileBytes);
outputStream.writeBytes("\r\n--" + boundary + "\r\n");
outputStream.writeBytes("Content-Disposition: form-data; name=\"upfile\"; filename=\"" + file.getName() + "\"\r\n");
outputStream.writeBytes("Content-Type: application/octet-stream\r\n\r\n");
outputStream.write(fileBytes);
}
public static void setFileByBase64(DataOutputStream outputStream, String base64, String fieldName) throws Exception {
byte[] decodedBytes = Base64.getDecoder().decode(base64);
outputStream.writeBytes("\r\n--" + boundary + "\r\n");
outputStream.writeBytes("Content-Disposition: form-data; name=\"upfile\"; filename=\"" + fieldName + "\"\r\n");
outputStream.writeBytes("Content-Type: application/octet-stream\r\n\r\n");
outputStream.write(decodedBytes);
}
}