Skip to Content
author's profile photo Former Member
Former Member

FileUpload - Checking Resource data prior to upload

Hi All,

Is there a way of examining the Resource data before a file is uploaded, i.e. to prevent them uploading files above a certain size or with a certain extension? I can't see how I can do this until the file has already been uploaded.



Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on May 27, 2008 at 09:03 AM

    // for checking the size of the resource use the following code.

    public byte[] getByteArray(InputStream ipStr) {

    byte[] bytArr = null;

    try {

    bytArr = new byte[ipStr.available()];

    } catch (IOException e) {



    try {;

    } catch (IOException e1) {



    return bytArr;


    // getting the resource that user has browsed

    IWDResource resource = element.getResDocumentUploaded();

    // Getting the byte array of the resource selected

    byte[] arrBIN = getByteArray(;

    //checking If file size is less than 25 MB

    if(arrBIN.length < 25 * 1024 * 1024)



    Using this code we can check if file uploaded is less than 25MB


    for getting file extension of document uploaded one can use the following code

    ublic static java.lang.String getFileExtension(

    java.lang.String strResourceName) {

    String strExtension = null;

    int iIndex = strResourceName.lastIndexOf(".");

    strExtension = strResourceName.substring(iIndex + 1);

    return strExtension;


    IWDResource resource = element.getResDocumentUploaded();

    String strResource = resource.getResourceName();

    String strExtension = getFileExtension(strResource);

    one can create another input fiels wich takes in the extension of the uploaded file and compare it with strExtension

    string application = context_of_field acceptingextension




    Please do provide me points if this helps you .Thank you

    Edited by: rohan Henry on May 27, 2008 11:05 AM

    Edited by: rohan Henry on May 27, 2008 11:08 AM

    Edited by: rohan Henry on May 27, 2008 11:09 AM

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on May 27, 2008 at 04:53 AM


    There is a difference between uploading the file to the context and saving it in the file system.

    Say you are working in NW2004, you have a fileResource (type byte) in your context.

    fileResource is bound the file upload element.

    When user uploads a file it is saved in the context.

    From there, you can check it size (something like wdContext.currentContextElement().getFileResource().length

    According to the length you can save it in the file system or display an error message regarding its size...



    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.