Copy link to clipboard
Copied
Hi!
I have already read all the forum posts related to this topic ... but unfortunately I can't upload a binary file through socket (js for indesign CC2017, os 10.13.3).
The answer of server is always 400 Bad Request
I enclose the code ...
Where I'm wrong?Thanks!
sendDataToServerLocal("~/Desktop/prova.pdf", "prova")
function sendDataToServerLocal(filepath, filename) {
conn = new Socket;
reply = "";
// Read file
var f = File(filepath);
f.encoding = 'BINARY';
f.open("r");
var fContent = f.read();
f.close();
// Connect to server
if (conn.open("192.168.1.125:80", "BINARY")) {
conn.timeout = 20000;
boundary = Math.random().toString().substr(2);
content = "--" + boundary
+ "Content-Disposition: form-data; name=\"file\"; filename=\"" + filename + ".pdf\"\r\n"
+ "Content-Type: application/octet-stream\r\n"
+ "\r\n"
+ fContent;
cs = "POST mb_riediting2/php/upload.php HTTP/1.0\r\n"
+ "Content-Length: " + content.length + "\r\n"
+ "Content-Type: multipart/form-data; charset=utf-8; boundary=" + boundary + "\r\n"
+ "Host: 192.168.1.125:80\r\n"
+ "User-Agent: Apache-HttpClient/4.3.1 (java 1.5)\r\n"
+ "Accept: */*\r\n"
+ "Expect: 100-continue\r\n"
+ "\r\n"
+ content
+ "--" + boundary + "--\r\n"
conn.write(cs);
reply = conn.read(999999);
conn.close();
alert(reply)
if (reply.indexOf("200 OK") > 0) {
alert("File successfully uploaded!");
} else {
//throw new Error("Error:" + reply);
}
} else {
// throw new Error("Can't connect to server");
}
}

Copy link to clipboard
Copied
Wouldn't that be stronger to use cURL ?
Copy link to clipboard
Copied
Have you find a way to do finally ?
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more