commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Giovannini Andrea" <Andrea.Giovann...@formula.it>
Subject R: NEWBIE FileUpload question
Date Wed, 07 Apr 2004 14:35:39 GMT
Hi,
I'm still fighting with file uploading... I've captured the raw HTTP request (that's the upload
of an excel file) but it looks ok... I just can't understand what's wrong with it...
The problem is still raised in MultiPartStream.discardBodyData() which throws a MalformedStreamException("Stream
ended unexpectedly"). This is the code which raises the exception

---------------- begin snippet -----------------------------------
                    // The last pad amount is left in the buffer.
                    // Boundary can't be in there so signal an error
                    // condition.
                    total += pad;
                    throw new MalformedStreamException("Stream ended unexpectedly");
---------------- end snippet --------------------------------------

Any idea?
Thanks again,
Andrea

P.S.
This is my request

------------------------------ begin raw request ----------------------------------------------------------
POST /dnext/datacontroller?dic=pricelistitems&method=upload&action=importExcel&dkey=SUC1100001%20%200004&type=01&versionNumber=1&fileName=PPP.csv
HTTP/1.1
Accept: */*
Accept-Language: it
Referer: http://localhost:8080/myapp/importExcel.jsp?&dkey=0001%20%200004&type=01&versionNumber=1
Content-Type: multipart/form-data; boundary=---------------------------ThIs_Is_tHe_bouNdaRY_
Content-Disposition: filename=PPP.csv
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Host: localhost:8080
Content-Length: 791
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: JSESSIONID=F802FC9DDA8C920BD51D6AC9D3E787BB

PARAMETRI DI ESTRAZIONE;;;;;;;;;;; Tipologia;Chiave1;Chiave2;Chiave3;Versione;;;;;;;
01;SU;C1100001;0004;2;;;;;;;
;;;;;;;;;;;
Articolo;Descrizione;Prezzo unitario;Decorrenza;Scadenza;Unità di Misura;Unità di Misura
D;Sconto1;Sconto2;Sconto3;Sconto4;Sconto5
5302;ARTICOLO 5302;2;15/10/2003;30/11/2004;CT;CARTONI;1,00;2,00;3,00;0;0
5302;ARTICOLO 5302;2;15/10/2003;30/11/2004;CT;CARTONI;2,00;0;0;0;0
5302-1;ARTICOLO 5302;3;15/10/2003;30/11/2004;CT;CARTONI;1,00;2,00;3,00;0;0
5302-1;ARTICOLO 5302;2;15/10/2003;30/11/2004;CT;CARTONI;0;0;0;0;0
5302-1;ARTICOLO 5302;2;15/10/2003;30/11/2004;CT;CARTONI;0;0;0;0;0
5302-1;ARTICOLO 5302;2;15/10/2003;30/11/2004;CT;CARTONI;0;0;0;0;0
5302-P1;ARTICOLO 5302;3;15/10/2003;30/11/2004;CT;CARTONI;0;0;0;0;0
------------------------------ end raw request ------------------------------------------------------------

> -----Messaggio originale-----
> Da: Martin Cooper [mailto:martinc@apache.org]
> Inviato: martedì 6 aprile 2004 21.10
> A: commons-user@jakarta.apache.org
> Oggetto: Re: NEWBIE FileUpload question
> 
> 
> I am not at all familiar with the XMLHTTP code you are using
> to create the request, but I'm guessing that the problem may 
> lie in the structure of the request itself. If you could 
> capture the raw request that is being submitted (e.g. using 
> Windows Network Monitor or Ethereal), that would help a lot.
> 
> --
> Martin Cooper
> 
> 
> "Giovannini Andrea" <Andrea.Giovannini@formula.it> wrote in
> message 
> news:192D0B4A713A704895EACB84234B62653AA75C@hulk2000.gformula.net...
> Hi,
> I'm using FileUpload to process a file uploaded from Internet 
> Explorer via Jscript, there's no direct form submit but I use 
> the XMLHTTP object since I want control over the result. This 
> is my client code
> 
> function go() {
>     // I skip some details
>     var fileName = ...;
>     var url = ... + "&fileName=" + fileName;
> 
>     var adoStream = new ActiveXObject("ADODB.Stream");
>     adoStream.Mode = 3;
>     adoStream.Type = 1;
>     adoStream.Open();
>     adoStream.LoadFromFile(fileName);
>     var xmlhttp = new ActiveXObject("MSXML2.XMLHTTP");
>     xmlhttp.open("POST", url, false);
> 
>     var boundary = "----------This_Is_The_Boundary_\r\n";
>     xmlhttp.setRequestHeader("Content-Type","multipart/form-data;
> boundary=" + boundary);
>     xmlhttp.setRequestHeader("Content-Length", adoStream.Size);
>     xmlhttp.send(adoStream.Read(adoStream.Size));
> }
> 
> Then I want to save the file on the server. In my servlet I have this
> code:
> 
> String path = ...
> DiskFileUpload upload = new DiskFileUpload();
> upload.setRepositoryPath(path);
> 
> try {
> List items = upload.parseRequest(request);
> Iterator iter = items.iterator();
> while (iter.hasNext()) {
> FileItem item = (FileItem) iter.next();
> if (!item.isFormField()) {
> fileName = item.getName();
> File uploadedFile = new File(fileName);
> item.write(uploadedFile); } } } catch(Exception e) { ... }
> 
> But the parseRequest() returns an empty list. I've debugged
> the FileUpload code and the problem is that in the 
> discardBodyData() of the class MultipartStream a 
> MalformedStreamException("Stream ended
> unexpectedly") is thrown and parseRequest() returns an empty 
> collection. So I wonder what's wrong with my uploading... Any idea?
> 
> Thanks in advance,
> Andrea
> 
> ----------------------------------
> Andrea Giovannini
> Java Software Architect
> 
> Gruppo Formula S.p.A.
> ----------------------------------
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message