Article View: adobe.scripting.indesign
Article #1694Re: How to upload a file
From: Tino Runtzler
Date: Wed, 04 Feb 2009 07:50
Date: Wed, 04 Feb 2009 07:50
82 lines
3756 bytes
3756 bytes
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:
[code]
File:
[/code]
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:1.9.0.5) 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
-----------------------------41184676334
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;
http.execute();
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.open("localhost:7070");
conn.timeout=300;
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("");
conn.writeln("-----------------------------1255014013694");
conn.writeln('Content-Disposition: form-data; name="uploadFile"; filename="test.txt"');
conn.writeln("Content-Type: text/plain");
conn.writeln("");
conn.writeln("test");
conn.write("-----------------------------1255014013694--");
var i=1;
while(!conn.eof) {
$.writeln(i + ":" + conn.eof + ":" + conn.readln());
++i;
};
conn.close();
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
Technical Details
Message-ID:
<59b78d9a.2@webcrossing.la2eafNXanI>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!newshub.sdsu.edu!webcrossingReferences:
<59b78d9a.-1@webcrossing.la2eafNXanI>Show Full Headers
Complete Article Headers
X-Google-Thread: f939a,ef5800930bb02dd7 X-Google-Attributes: gidf939a,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII From: "Tino Runtzler" <tino.runtzler@bauerverlag.de> Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!newshub.sdsu.edu!webcrossing Newsgroups: adobe.scripting.indesign Subject: Re: How to upload a file Message-ID: <59b78d9a.2@webcrossing.la2eafNXanI> Date: Tue, 3 Feb 2009 23:50:24 -0800 References: <59b78d9a.-1@webcrossing.la2eafNXanI> Lines: 98 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit