6 Replies Latest reply on Apr 8, 2011 2:36 AM by Pelmo77

    How to upload a file


      I am working on a project which uses remote indesign server.

      The javascript is executed at remote end and retrieves the file using java servlet.

      var http1 = new HttpConnection("");
      http1.response = new File("test.indd") ;
      http1.execute() ;
      http1.response.close() ;

      after downloading the file I am converting indesign file to PDF. Now I have to upload this PDF to my java server using a fileupload servlet.

      How I can achieve this using HttpConnection ?

      Please help. Thanks.

        • 1. Re: How to upload a file
          Level 1
          Hi Venkateswara Rao,

          ok, where do you get HttpConnection from? Didn't find it in Core JavaScript Classes as well as in Adobe Indesign CS3 Classes?! Or is it an own written wrapper object?

          To call a fileupload servlet, you could painfully implement http, ftp, smtp, .. on your own by using the Socket object from Core JavaScript Classes. I did this approach for http as well as smtp.

          Cheers Tino
          • 2. Re: How to upload a file
            Level 1
            Hi Cheers Tino,

            I found HttpConnection in Javascript CS3 tools guide.

            I was able to download a file from server using HttpConneciton, but unable to upload file to server using it.

            I tried bunch of things creating "HTTP 1.1/ POST" packet, but
            nothing worked. I am very new to this kind of packet creation."

            Can you please provide me with the file upload script.

            Your help is greatly appreciated.

            • 3. Re: How to upload a file
              Level 1
              Hi Venky,

              unfortunately i must admit, that i did found a solution for uploading a file neather with HttpConnection nor with Socket.

              I tried the following:

              1. Setup a servlet for uploading, build a small HTTP form and inspect the HTTP-Header:

              <form enctype="multipart/form-data" action="FileUploader" method="POST">
              File: <input name="uploadFile" type="file">
              <input type="submit" value="upload">

              HTTP-Header(truncated, only first bytes displayed):
              POST /FileUploadServlet/FileUploader HTTP/1.1
              Host: localhost:7070
              User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv: Gecko/2008120122 Firefox/3.0.5 (.NET CLR 3.5.30729)
              Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
              Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3
              Accept-Encoding: gzip,deflate
              Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
              Keep-Alive: 300
              Connection: keep-alive
              Referer: http://localhost:7070/FileUploadServlet/index.jsp
              Cookie: JSESSIONID=0359fed1cc75cb347491ac227deb; _csuid=49057dd60a38b213
              Content-Type: multipart/form-data; boundary=---------------------------41184676334
              Content-Length: 37953

              Content-Disposition: form-data; name="uploadFile"; filename="mytestpicture.jpg"
              Content-Type: image/jpeg

              ÿØÿ ...

              This upload works fine, the servlet get the right information to save the uploaded file.

              2. Try to upload a file with HttpConnection

              var http = new HttpConnection("http://localhost:7070/FileUploadServlet/FileUploader" ) ;
              var fileToTransfer = new File("mytestpicture.jpg") ;
              http.requestheaders = ["Keep-Alive" , "300"] ;
              http.method = "POST";
              http.mime = "multipart/form-data;";
              http.chunked = false;
              http.request = fileToTransfer;

              This doesn't work. The HttpConnection doesn't write any boundary or Content-Disposition information, so the servlet can't find the file content.

              3. Try to upload afile with Socket

              var conn = new Socket();
              conn.writeln("POST /FileUploadServlet/FileUploader HTTP/1.1");
              conn.writeln("Host: localhost:7070");
              conn.writeln("Keep-Alive: 300");
              conn.writeln("Connection: keep-alive");
              conn.writeln("Referer: http://localhost:7070/FileUploadServlet/");
              conn.writeln("Content-Type: multipart/form-data; boundary=---------------------------1255014013694");
              conn.writeln("Content-Length: 211");
              conn.writeln('Content-Disposition: form-data; name="uploadFile"; filename="test.txt"');
              conn.writeln("Content-Type: text/plain");
              var i=1;
              while(!conn.eof) {
              $.writeln(i + ":" + conn.eof + ":" + conn.readln());

              This doesn't work. I tried to define an own boundary and set the Content-Disposition etc. by myself. For testing i used in this case no binary but a text file.

              So Venky, perhaps i inspired you on further examination. Or perhaps Robin Mills got an idea on this issue (http://www.clanmills.com/robin.shtml) ;-) or any forum guru?!

              Cheers Tino
              • 4. Re: How to upload a file
                Level 1
                Hi Tino,

                I have finally made it. I just searched for C Socket example and mapped it to indesign scripting (javascript ) and it worked.

                Thank you so much for giving response.
                Your help is very much appreciated.

                • 5. Re: How to upload a file
                  fivan Level 1

                  Hi Venky


                  I have to upload images using indesign scripting.


                  Can you report an example of the script you made or just an help?

                  thanks in advance.



                  • 6. Re: How to upload a file

                    You'll find a documented solution with socket here : http://blog.boceto.fr/2011/04/07/indesign-script-upload-de-fichier/