Maybe a mistake?
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
986214bf66
commit
f10e80c7f7
121
sigServer.java
121
sigServer.java
@ -84,71 +84,73 @@ public class sigServer {
|
|||||||
if (boundary.length()>0) {
|
if (boundary.length()>0) {
|
||||||
if (line.equals(boundary)) {
|
if (line.equals(boundary)) {
|
||||||
truncateUntilBoundary=true;
|
truncateUntilBoundary=true;
|
||||||
|
System.out.println("Boundary found.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else
|
|
||||||
if (line.contains("Content-Disposition: ")||line.contains("Content-Type: ")) {
|
|
||||||
if (line.contains("filename=")) {
|
|
||||||
filename=line.substring(line.indexOf("filename=")+"filename=".length()+1);
|
|
||||||
filename = filename.substring(0,filename.length()-1);
|
|
||||||
int dotPosition=0;
|
|
||||||
if (filename.contains(".")) {
|
|
||||||
for (int i=filename.length()-1;i>=0;i--) {
|
|
||||||
if (filename.charAt(i)=='.') {
|
|
||||||
dotPosition=i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
filename="upload"+System.nanoTime()+filename.substring(dotPosition);
|
|
||||||
System.out.println("Filename: "+filename);
|
|
||||||
} else {
|
|
||||||
System.out.println(line);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
File myFile = new File(new File(sigPlace.OUTDIR,sigPlace.UPLOADSDIR),filename);
|
if (line.contains("Content-Disposition: ")||line.contains("Content-Type: ")) {
|
||||||
// check if file exist, otherwise create the file before writing
|
if (line.contains("filename=")) {
|
||||||
myFile.mkdirs();
|
filename=line.substring(line.indexOf("filename=")+"filename=".length()+1);
|
||||||
if (!myFile.exists()) {
|
filename = filename.substring(0,filename.length()-1);
|
||||||
myFile.createNewFile();
|
int dotPosition=0;
|
||||||
} else {
|
if (filename.contains(".")) {
|
||||||
myFile.delete();
|
for (int i=filename.length()-1;i>=0;i--) {
|
||||||
myFile.createNewFile();
|
if (filename.charAt(i)=='.') {
|
||||||
}
|
dotPosition=i;
|
||||||
stream = new FileOutputStream(myFile);
|
break;
|
||||||
char[] buffer = new char[1024];
|
}
|
||||||
int count;
|
}
|
||||||
boolean wroteData=false;
|
}
|
||||||
while ((count = in.read(buffer))>0) {
|
filename="upload"+System.nanoTime()+filename.substring(dotPosition);
|
||||||
//stream.write(in.read(buffer));
|
System.out.println("Filename: "+filename);
|
||||||
//stream.write(buffer.,0,count);
|
} else {
|
||||||
String buf = new String(buffer);
|
System.out.println(line);
|
||||||
byte[] data = buf.getBytes("ISO-8859-1");
|
|
||||||
stream.write(data,0,count);
|
|
||||||
wroteData=true;
|
|
||||||
if (buf.contains(boundary)) {
|
|
||||||
System.out.println("");
|
|
||||||
System.out.println("<...>");
|
|
||||||
System.out.println("");
|
|
||||||
System.out.println(new String(data,StandardCharsets.UTF_8));
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
stream.close();
|
File myFile = new File(new File(sigPlace.OUTDIR,sigPlace.UPLOADSDIR),filename);
|
||||||
|
// check if file exist, otherwise create the file before writing
|
||||||
|
myFile.mkdirs();
|
||||||
|
if (!myFile.exists()) {
|
||||||
|
myFile.createNewFile();
|
||||||
|
} else {
|
||||||
|
myFile.delete();
|
||||||
|
myFile.createNewFile();
|
||||||
|
}
|
||||||
|
stream = new FileOutputStream(myFile);
|
||||||
|
char[] buffer = new char[1024];
|
||||||
|
int count;
|
||||||
|
boolean wroteData=false;
|
||||||
|
while ((count = in.read(buffer))>0) {
|
||||||
|
//stream.write(in.read(buffer));
|
||||||
|
//stream.write(buffer.,0,count);
|
||||||
|
String buf = new String(buffer);
|
||||||
|
byte[] data = buf.getBytes("ISO-8859-1");
|
||||||
|
stream.write(data,0,count);
|
||||||
|
wroteData=true;
|
||||||
|
if (buf.contains(boundary)) {
|
||||||
|
System.out.println("");
|
||||||
|
System.out.println("<...>");
|
||||||
|
System.out.println("");
|
||||||
|
System.out.println(new String(data,StandardCharsets.UTF_8));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stream.close();
|
||||||
|
|
||||||
if (!wroteData) {
|
if (!wroteData) {
|
||||||
System.out.println("Upload failed!");
|
System.out.println("Upload failed!");
|
||||||
in.close();
|
in.close();
|
||||||
CreateRequest(client,"400","Bad Request",Paths.get(sigPlace.OUTDIR,"testfile.html"));
|
CreateRequest(client,"400","Bad Request",Paths.get(sigPlace.OUTDIR,"testfile.html"));
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
System.out.println("Saving upload to "+sigPlace.UPLOADSDIR+" directory.");
|
System.out.println("Saving upload to "+sigPlace.UPLOADSDIR+" directory.");
|
||||||
if (filename.contains(".png")) {
|
if (filename.contains(".png")) {
|
||||||
ArcadeReader.submitToDatabase(Paths.get(sigPlace.OUTDIR,sigPlace.UPLOADSDIR,filename));
|
ArcadeReader.submitToDatabase(Paths.get(sigPlace.OUTDIR,sigPlace.UPLOADSDIR,filename));
|
||||||
System.out.println("Submitted to the database!");
|
System.out.println("Submitted to the database!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
filename=null;
|
||||||
}
|
}
|
||||||
filename=null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (line.contains("Content-Length: ")) {
|
if (line.contains("Content-Length: ")) {
|
||||||
@ -157,8 +159,7 @@ public class sigServer {
|
|||||||
}
|
}
|
||||||
if (line.contains("Content-Type:")) {
|
if (line.contains("Content-Type:")) {
|
||||||
if (line.contains("Content-Type: multipart/form-data; boundary=")) {
|
if (line.contains("Content-Type: multipart/form-data; boundary=")) {
|
||||||
boundary=line.substring("Content-Type: multipart/form-data; boundary=".length());
|
boundary="--"+line.substring("Content-Type: multipart/form-data; boundary=".length());
|
||||||
System.out.println("Boundary set to "+boundary);
|
|
||||||
} else
|
} else
|
||||||
if (line.contains("application/json")){
|
if (line.contains("application/json")){
|
||||||
isApplication=true;
|
isApplication=true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user