I'm trying to implement a file upload out of InDesign with it's built in JavaScript technology.
Basically the script exports an InDesign document to a PDF and then tries to upload the file to a webserver. For the upload I use the extendables plugin which handles the HTTP request.
I was able to make some basic GET and POST requests, but I'm failing to make a POST request for the file upload.
Here's the basic code:
var req = new http.HTTPRequest("POST", "http://mysite.com);
var type = "application/pdf";
var boundary = "--012345678910";
var myTitle = "\r\nContent-Disposition: form-data; name=\"title\"\r\n\r\n"+title+"\r\n"+boundary;
var myFile= "\r\nContent-Disposition: form-data; name=\"file\"; filename=\""+pdfFileName+"\"\r\nContent-Type: "+type+"\r\n\r\n"+file_contents+"\r\n"+boundary+"--";
var myData = boundary + myTitle + myFile;
req.content(myData);
req.header("User-Agent", "MyUserAgent");
req.header("Content-Type", "multipart/form-data; boundary=012345678910");
// make request
res = req.do();
I was able to upload the same file with the same headers and so on from a Ruby script and some REST clients.
It seems that the form data is not included in the post parameters when I look at what arrives at the server.
So my question is if anyone has ever successfully uploaded a file using InDesign JavaScript and the extendables plugin. The extendables documentation is not really helpful, maybe I'm missing something. I'm also open for alternatives.
No comments:
Post a Comment