4

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.

mathz
  • 136
  • 1
  • 1
  • 9
  • Any updates since the post? – David Apr 24 '15 at 22:12
  • If you have access to Adobe Bridge/Bridgetalk, I would look into using Bridge's HttpConnection object. Looking at the Bridge CS6 Javascript reference (from the Bridge SDK), it appears that the HttpConnection object has support for file uploads (I think via File objects) and POST requests. You can call Bridge from InDesign sort of like these: https://gist.github.com/daluu/2d9dec72d0863f9ff5a7 and https://gist.github.com/mericson/6509997 – David Apr 24 '15 at 22:18

0 Answers0