Watch Build the Pumpjack Pro Sample App Webinar
Results 1 to 4 of 4

Thread: Uploading DOCX files fails, solved

  1. #1
    Real Name
    Irwin Cohen
    Join Date
    Oct 2009
    Brooklyn, NY, USA

    Default Uploading DOCX files fails, solved

    My users routinely upload files of type *.txt, *.doc and *.pdf, using code based on the sample in the Alpha documentation (
    dim msg as c = ""
    if eval_valid("cmd") 'del last byte, always added in upload -- this is the added line of code.
        file.from_blob(ServerSetting.Document_Root + "\\" + FileToUpload.filename,
        msg = "<a href=\"/" + FileToUpload.filename + "\" target=\"_blank\">" + FileToUpload.filename + "</a> was uploaded<br /><br />"
    end if
    <title>File Upload example</title>
    <body bgcolor="#ffffff">
    <%a5 ? msg %>
    <form action=" <%a5 ? request.script_name %> " method="POST" enctype="multipart/form-data">
    <input type="file" name="FileToUpload" value=""><br />
    <input type="submit" name="cmd" value="Upload File">
    But this method fails for *.docx files. The uploaded file can not be opened by ms word and can not be processed by some file conversion programs like Doxillion (word to pdf converter). After several hours I found the problem and the solution is simple but not obvious so others might find it useful. The upload process using, enctype="multipart/form-data", always adds one null byte to the end of the upload so the file saved is one byte longer than the original. This extra null byte does not seem to make any difference for some file types but makes *.docx files unusable. The simple solution is to remove the last byte before the uploaded data is saved as a file.
    The one additional line of code is: 'del last byte, always added in upload
    I have not seen this effect on file validity mentioned before and it may affect other file types also.
    Thanks for reading and for all the helpful information I have found on this board.

  2. #2
    Real Name
    Lee Vasic
    Join Date
    May 2010
    Salt Lake City

    Default Re: Uploading DOCX files fails, solved.

    Thank you for sharing. I'm sure that took a few hours of research.

  3. #3
    Alpha Software Employee Lenny Forziati's Avatar
    Real Name
    Lenny Forziati
    Join Date
    Nov 2001
    Alpha Software

    Default Re: Uploading DOCX files fails, solved.

    Note that directly accessing is a deprecated technique. Referencing this property will force all of the data to be loaded into memory.
    If you have many sessions active at once, this could potentially consume all available virtual memory on your server and result in errors.
    To save uploaded data to a file, use the SaveToFile function rather than referencing the Data property directly.


    We recommend that you not directly reference uploaded file Data property values greater than 1024 bytes.
    Use the length property of the UploadedFile object to determine the actual size of uploaded data.

    Lenny Forziati
    Vice President, Internet Products and Technical Services
    Alpha Software Corporation

  4. #4
    Alpha Software Employee Beta Spark's Avatar
    Real Name
    Sarah Mitchell
    Join Date
    Jul 2015

    Default Re: Uploading DOCX files fails, solved.

    For updated information on uploading files to the Application Server using xbasic, see "Uploading Files to the Application Server". This document has been updated to provide examples using the INET::UploadedFile class as well as using Storage containers.
    Sarah Mitchell

    Try our NEW Help System! Now Available at

    Is an article missing from our Documentation?
    Can't find what you're looking for?
    REPORT IT to documentation [at] - Tell us what's missing, and we'll track it down for you.

Similar Threads

  1. Uploading files from a UX
    By twwtc in forum Mobile & Browser Applications
    Replies: 19
    Last Post: 01-23-2017, 10:02 PM
  2. uploading files
    By johnm in forum Web Application Server v7
    Replies: 2
    Last Post: 08-29-2006, 04:36 AM
  3. Uploading files to the WAS, jpg or pdf only?
    By David Priest in forum Web Application Server v7
    Replies: 0
    Last Post: 07-31-2006, 07:40 AM
  4. Uploading files
    By John Costello in forum Alpha Five Version 5
    Replies: 10
    Last Post: 06-21-2005, 05:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts