This topic is locked
[SOLVED]

Trouble with downloading files through app that were not uploaded through app

5/2/2024 6:28:13 PM
PHPRunner General questions
V
valdaure author

Hi All,

I have created a PHP cron job that: 1) checks for new emails in the Invoices folder of my email Inbox, 2) runs a database query to find the supplier ID based sender email address, 3) extracts email attachments, 4) saves the files to disk with a unique name in order to ovoid overwriting files with the same name (as PHPRunner does), 5) and then inserts a record into the table of invoices for processing. This is all done by a series of Custom Files created within PHPRunner, but which are 100% custom code (with help from ChatGPT), so no PHPRunner APIs or other functionality are used.

I view the list of invoices for processing through my PHPRunner app, but of course the new database records and file uploads were not done through the app. I believe I have formatted the value in the 'file' column to match the Json used by PHPRunner. The actual files on the disk are healthy (encoded/decoded correctly), as they can be downloaded manually and opened with no problem.

However, when trying to download the files through my PHPRunner app, the download fails. The message from Chrome is to check my connection to the server.

Have I missed a step in making my database entries and files on disk usable by mfhandler.php (assuming this is where the problem lies) ?

Here's an example of how the file colum value appears in my database table:

[{"name":"files\/invoices_test\/INV-000114_n6rev3q4.pdf","usrName":"INV-000114.pdf","size":38950,"type":"application\/pdf","searchStr":"INV-000114.pdf,!:sStrEnd"}]

Is correctly formatted Json in the file column with path to healthy files not enough?

Let me know if more information is needed to understand my issue.

Thanks for your help.

V

admin 5/6/2024

When you upload files manually, outside of PHPRunner app, you need to create a JSON record in the database in the exact format that PHPRunner expects. Make sure that file size is specified also.

V
valdaure author 5/6/2024

Thanks for the reply. I did precisely as suggested (see my original question). There is no difference between the database entry in Json format generated by my custom script and the entry generated by PHPRunner (other than random string tagged on to the file name to make the name unique).

Your reply nonetheless give me a new potential problem to investigate: how the file size is calculated. Indeed, if the file size as stored in the database is not calculated correctly, the file download fails. My custom script was not calculating the file size correctly. My script was calculating the size of the email file attachment before it was stored in the server's file system. When I modified my script to determine the size of the file as stored on the disk, and include that file size in the database, the files download as expected.

Thanks for giving me an idea that led me to the solution.

admin 5/6/2024

Perfect, thank you for the update! Yes, file size is important.