/
Uploaded file lost on validation error on 5.2.1-B1

Uploaded file lost on validation error on 5.2.1-B1

In one of projects I was working on I replaced a regular uploader (used for file uploading on "Files" tab during article adding/editing) with flash uploader. After doing so I've faced a problem with uploaded file being lost in case if I haven't filled in one of required fields on that form. Actual file in fact was successfully uploader under /system/tmp folder.

In In-Portal 5.2.1-B1 and up we've significantly changed how uploaded files are stored till the moment, when item (e.g. article), where they belong to will be saved from a temporary table to a live table. Now all uploaded files stay under /system/tmp and aren't copied to live folder and they info is stored in session.

After debugging I've found mismatch of used session variable names:

  • saved into: n-file[][FilePath]_file_info52
  • read from: n-file[0][FilePath]_file_info52

This issue is fixed in wrong_upload_info_in_session_fix.patch patch.

After I've fixed and saved sub-item in temporary table and then tried to edit it again (not saved to live table yet) I saw no files, but I'm sure I've uploaded one before. It turned out to be the same problem with session variable naming, but "-1" ID was used instead of 0:

  • saved into: n-file[0][FilePath]_file_info52
  • read from: n-file[-1][FilePath]_file_info52

This happened, because kDBItem::setTempID changed sub-item ID (in temporary table) from 0 to -1. If I repeat procedure, then 0 will be changed to -2 and so on.

To fix this we need also rename a session variable, where uploaded file information is stored.