IBM webMethods Hybrid Integration

IBM webMethods Hybrid Integration

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
Expand all | Collapse all

HTTP uploading a binary file to IS

  • 1.  HTTP uploading a binary file to IS

    Posted Thu February 01, 2007 03:33 AM

    IS can handle most HTTP POSTs just fine, but binary file uploads are tricky. Just thought I’d put together a thread on the steps I took to get it running.

    Also see an older thread:
    “HTTP File upload”
    [url]wmusers.com

    This is a thread on downloading binary files from IS:
    “Downloading a binary file through an IS service”
    [url]wmusers.com

    1. Ensure you have webMethods’ multipart content handler installed
    webMethods has developed a content handler for multipart/form-data HTTP POSTs. I understand it is automatically installed by the IS 6.x package WmBrokerAdmin that uses it for ADL file uploads. If the handler is not installed, webMethods can supply a zip package named ContentHandler.zip which contains JAR files from WmBrokerAdmin. This is a 6.x package, but it works fine on IS 4.6.

    2. Create the HTML form for your file upload.
    Note, the FORM element ‘enctype’ attribute must be set to “multipart/form-data” and INPUT element must be of type ‘file’. For eg:
    [html]

    [/html] When you test this in your browser, a 'Browse' button automatically appears next to the file input element.

    3. Access the uploaded data
    I chose to name the HTML file input element “uploadFile”, but you can name it anything you like. When the file is uploaded, the multipart content handler automatically inserts a record with the same name (‘uploadFile’ in my case) into the pipeline. The record structure looks like this:

    uploadFile  (Record)
    uploadFile/filename (string)
    uploadFile/data  (object)
    uploadFile/type (string)

    The handler also inserts in an array of ‘uploadFileList’ records – this is how WM caters to multiple elements in an HTML form having the same name.

    You now need to define an appropriately named record with this structure as the input specification of the upload receive service. You can now access data in <record_name>/data, which is a java byte array. For instance, this is Java code for a service that will take the data and write it to disk:

    // pipeline
    IDataCursor pipelineCursor = pipeline.getCursor();
    String	fileName = IDataUtil.getString( pipelineCursor, "fileName" );
    byte[]	contentBytes = (byte []) IDataUtil.get( pipelineCursor, "data" );
    pipelineCursor.destroy();
    
    // pipeline
    
    try {
    FileOutputStream fos = new FileOutputStream(fileName);
    fos.write(contentBytes);
    }
    catch (Exception e) {throw new ServiceException(e);}

    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 2.  RE: HTTP uploading a binary file to IS

    Posted Tue February 06, 2007 11:41 PM

    A quick update to my post above:

    If you run into problems submitting the HTML form containing the file upload, try removing any Javascript submits for the form. i.e don’t submit the form using the Javascript call “document..submit()” - just use a plain HTML submit. My suspicion is that somehow Javascript resets the form’s enctype back to the default: “application/x-www-form-urlencoded”.


    #Integration-Server-and-ESB
    #Flow-and-Java-services
    #webMethods


  • 3.  RE: HTTP uploading a binary file to IS

    Posted Wed April 25, 2007 09:37 PM

    Sonam,

    Can you provide me the ContentHandler.zip?

    Thanks in advance

    Kevin


    #Flow-and-Java-services
    #webMethods
    #Integration-Server-and-ESB


  • 4.  RE: HTTP uploading a binary file to IS

    Posted Wed May 16, 2007 10:12 AM

    Hi Kevin - sorry, just saw your post now.

    I can’t provide the ContentHandler.zip as it is copyrighted by webMethods.

    However, you can get it from WM support.

    Regards,
    sonam


    #Flow-and-Java-services
    #webMethods
    #Integration-Server-and-ESB


  • 5.  RE: HTTP uploading a binary file to IS

    Posted Mon July 28, 2008 08:53 PM

    Hi Sonam

    I have the same issue about uploading the file using DSP which I couldn’t get the data in the uploaded file. I tried contacting the webMethods support guy to provide the ContentHandler.zip, but he said wm doesn’t ahave any package by that name.

    Could you please provide a link that I can download ContentHandler.zip ?

    Thanks
    Satish


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services


  • 6.  RE: HTTP uploading a binary file to IS

    Posted Mon August 11, 2008 01:44 AM

    Satish - Just saw your post. I can’t provide a link to ContentHandler.zip for the copyright reasons mentioned above.

    A HTTP POST for file upload (as executed for example, by the sample HTML form above), are of Content-Type ‘multipart/form-data’. webMethods’ default content handler does not handle these type of POSTs, but ContentHandler.zip does.

    The ContentHandler.zip file used to be automatically installed by the IS 6.x WmBrokerAdmin package and was used there to handle file uploads from an DSP admin webpage. If this package is not installed or available for your platform version, try asking webMethods to supply it or it’s equivalent for your platform. You can also try writing a content handler. As a last resort, try installing 6.1/6.5 WmBrokerAdmin via webMethods Installer and poaching the package from there. However, check with support, and test before you try this in production.


    #webMethods
    #Flow-and-Java-services
    #Integration-Server-and-ESB


  • 7.  RE: HTTP uploading a binary file to IS

    Posted Fri August 22, 2008 04:04 PM

    Thanks for the reply.

    I did this using mime services.

    Is there any that we can seperate the actual file content from the other field data that is sent in the same form?


    #webMethods
    #Flow-and-Java-services
    #Integration-Server-and-ESB


  • 8.  RE: HTTP uploading a binary file to IS

    Posted Fri August 29, 2008 02:39 PM

    Hi Satish,

    Can you please tell me in detail how you have done this using mime services.

    regards,
    Satya


    #webMethods
    #Flow-and-Java-services
    #Integration-Server-and-ESB


  • 9.  RE: HTTP uploading a binary file to IS

    Posted Tue July 28, 2009 06:11 PM

    Is there a way to verify that you have the right contenthandler installed & setup in your IS??

    Sonam - I followed all the steps that you mentioned, but I’m not able to get my I/p document populated with all the values…could you please help me give some pointers to where might be the issue? How could I verify the success of step 1


    #Integration-Server-and-ESB
    #Flow-and-Java-services
    #webMethods


  • 10.  RE: HTTP uploading a binary file to IS

    Posted Mon July 05, 2010 10:07 AM

    Hi All,

    After submit, i can get the data in my flowservice. But after clicking on submit button how will i take to next page which diplays successfully uploaded or return with error message from flowservice while uploading.

    Can someone please provide a solution to this.

    Thanks in advance.

    Regards,
    Naveen


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services


  • 11.  RE: HTTP uploading a binary file to IS

    Posted Tue July 06, 2010 07:14 AM

    You can make use of the Output template of the flowservice that you are invoking.


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services


  • 12.  RE: HTTP uploading a binary file to IS

    Posted Wed July 14, 2010 09:51 AM

    Hi Suren,

    Thanks for your reply.

    I tried using the output template, but after i upload the data and click on submit button a pop up appears with options to “open”, “save”, “cancel” and “more info”. If i open this i find my html code in this file. But it doesnt take me to the intended html page after uploading.

    Please help me on this. Your comments are valuable to me.

    Regards,
    Naveen


    #Flow-and-Java-services
    #webMethods
    #Integration-Server-and-ESB


  • 13.  RE: HTTP uploading a binary file to IS

    Posted Wed July 14, 2010 10:02 AM

    Naveen,

    If you could post the output template that you have in your service here, it would be easy for to know what is happening.

    BTW, this time did you get the file data in the pipeline…?


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services