jakarta-cactus-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Digital Monkey" <a...@digitalmonkey.co.uk>
Subject WebRequest / multipart/form-data
Date Thu, 30 May 2002 09:43:53 GMT
I may have a tidy solution to the multipart/form-data problem posed by
Gunnar Ole Skogen, using the HTTPClient classes from Ronald Tschalär
(http://www.innovation.ch/java/HTTPClient/) a block of code such as
below may be used to construct a multipart test example.

import HTTPClient.Codecs;
import HTTPClient.NVPair;
.
.
.
NVPair[] hdrs = new NVPair[1];

public void beginUpload(WebRequest theRequest) 
{
  NVPair[] opts = { new NVPair("option", "myoption") };
  NVPair[] file = { new NVPair("comment", "/home/alan/src.zip") };
  try {
    byte[] data = Codecs.mpFormDataEncode(opts, file, hdrs);
    InputStream i = new ByteArrayInputStream(data);
    theRequest.setUserData(i);
    theRequest.setContentType(hdrs[0].getValue());
    i.close();
  } catch (IOException e) {
    System.out.println("Error Building Multipart");
  }
}

If this helps anyone, please let me know - I would be happy to write up
a more detailed explanation for inclusion in the docs

Alan Perfect
DigitalMonkey
www.digitalmonkey.co.uk


--
To unsubscribe, e-mail:   <mailto:cactus-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:cactus-user-help@jakarta.apache.org>


Mime
View raw message