Skip to Content
avatar image
Former Member

downloading file


I'm trying to download a zipfile from a server using the downloadUI element. I have a context element of a binary type linked to the downloadUI element. I try to fill it like:


FileInputStream in = new FileInputStream(url);

ByteArrayOutputStream out = new ByteArrayOutputStream();

int length;

byte[] part = new byte [10 * 1024];

while ((length = != -1) {

out.write(part, 0, length);



IPrivateBasketView.IContextElement element = wdContext.currentContextElement();


}catch(IOException e){



The url of the zipfile is created through a webservice and looks something like this:

The problem is that i get the message that it cannot resolve the url (FileNotFoundException). The strange thing is that when i insert the url in the browser, it opens the zipfile but as text showing a screen with only wobbly characters instead giving the "save" dialog.

Can anyone tell me why i get the file not found and why it opens the zipfile as a textfile?

much thanks,


Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • Best Answer
    Jan 15, 2007 at 06:58 PM

    Hi Hugo,

    In order to read the content of a file through HTTP, you have to use a URLConnection instead; you can't use a FileInputStream.

    I'm not sure what your intention is, but it looks like you're trying to read the content of a file over HTTP on the server. You can't use a FileInputStream for that, you have to use a (Http)URLConnection instead. e.g.

      private static final int BUFFER_SIZE = 4 * 1024; // 4 KB
      // e.g. ""
      private byte[] getContent(String url) throws IOException {
        InputStream in = new URL(url).openStream();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        byte[] buf = new byte[BUFFER_SIZE];
        try {
          for(int i = 0; (i = != -1;) {
            out.write(buf, 0, i);
        } finally {
        return out.toByteArray();

    Then if you want to allow your clients to download that file you can indeed use a FileDownload UI element.

    Kind regards,


    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 15, 2007 at 03:09 PM


    maybe you need to set mime type using IWDModifiableBinaryType, sth like:

    // get attribute info for context attribute 'FileResource'

    IWDAttributeInfo attributeInfo =



    // create a modifiable binary type for the context attribute

    // which stores the MIME-object.

    IWDModifiableBinaryType binaryType =

    (IWDModifiableBinaryType) attributeInfo.getModifiableSimpleType();



    //store file data




    Add comment
    10|10000 characters needed characters exceeded