Alpha DevCon Engineering Roundtables
Results 1 to 5 of 5

Thread: Uploading DOCX files fails, solved

  1. #1
    Member
    Real Name
    Irwin Cohen
    Join Date
    Oct 2009
    Location
    Brooklyn, NY, USA
    Posts
    145

    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 (http://wiki.alphasoftware.com/Upload...ghlight=upload).
    Code:
    <html>
    <%a5
    dim msg as c = ""
    if eval_valid("cmd")
        FileToUpload.data.RESIZE(FileToUpload.data.SIZE()-1) 'del last byte, always added in upload -- this is the added line of code.
        file.from_blob(ServerSetting.Document_Root + "\\" + FileToUpload.filename, FileToUpload.data)
        msg = "<a href=\"/" + FileToUpload.filename + "\" target=\"_blank\">" + FileToUpload.filename + "</a> was uploaded<br /><br />"
    end if
    %>
    <head>
    <title>File Upload example</title>
    </head>
    <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">
    </form>
    </body>
    </html>
    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: FileToUpload.data.RESIZE(FileToUpload.data.SIZE()-1) '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.
    Irwin

  2. #2
    Member
    Real Name
    Lee Vasic
    Join Date
    May 2010
    Location
    Salt Lake City
    Posts
    978

    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
    Location
    Alpha Software
    Posts
    4,596

    Default Re: Uploading DOCX files fails, solved.

    Note that directly accessing FileToUpload.data 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.

    UploadedFile.SaveToFile(SaveFileName)

    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
    Posts
    376

    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

    Looking for answers? Try our documentation.
    If you can't find something, let us know!

  5. #5
    Member
    Real Name
    Wadim Korneev
    Join Date
    Dec 2016
    Posts
    4

    Default Re: Uploading DOCX files fails, solved

    To save uploaded data to a file, use the SaveToFile function rather than referencing the Data property directly.

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
  •