How to correctly add a file type input field in a suitecrm 8 instance?

Hello, I’m trying to add a file type field to a custom module. To this end, I have made the record view use legacy mode

config/services/module/module_routing.yaml

 my_custom_module:
   index: true,
   list: true,
   record: false

I have followed this guide.

Specifically from the guide I have implemented the following

At public/legacy/custom/Extension/modules/my_custom_module/Ext/Vardefs/file.php

<?php

$dictionary["my_custom_module"]["fields"]["filename"] = [
    'name' => 'filename',
    'vname' => 'LBL_FILENAME',
    'type' => 'file',
    'dbType' => 'varchar',
    'len' => '255',
    'reportable' => true,
    'comment' => 'File name associated with the note (attachment)',
    'importable' => false
];

$dictionary["my_custom_module"]["fields"]["file_mime_type"] = [
    'name' => 'file_mime_type',
    'vname' => 'LBL_FILE_MIME_TYPE',
    'type' => 'varchar',
    'len' => '100',
    'reportable' => true,
    'comment' => 'File name associated with the note (attachment)',
    'importable' => false
];

$dictionary["my_custom_module"]["fields"]["file_url"] = [
    'name' => 'file_url',
    'vname' => 'LBL_FILE_URL',
    'type' => 'varchar',
    'source' => 'non-db',
    'reportable' => false,
    'comment' => 'Path to file (can be URL)',
    'importable' => false
];

Then I repair and build and then add the new field in the module edit view.

The input file field is effectively added and the record is persisted. But in the detail view when I click on the file I get this message

Invalid File Reference

in this url

http://crm.local/legacy/index.php?preview=yes&entryPoint=download&id=7e3d9bbe-f612-b6bf-cc34-65cc3db2b552&type=my_custom_module

I also notice that there is no way to delete the attachment.

image

image

image

Thanks in advance for any ideas

File uploads are absolute pathing -

Try modifying your url to this

http://crm.local/public/legacy/index.php?preview=yes&entryPoint=download&id=7e3d9bbe-f612-b6bf-cc34-65cc3db2b552&type=my_custom_module

or this

http://crm.local/index.php?preview=yes&entryPoint=download&id=7e3d9bbe-f612-b6bf-cc34-65cc3db2b552&type=my_custom_module

And let me know what happens - I’ve touched on uploads a few times when generating reports and having already uploaded files made available in different modules and i’ve always fallen over at the absolute pathing bit a few times.

Check the file name 7e3d9bbe-f612-b6bf-cc34-65cc3db2b552 also exists within

/var/www/html/suitecrm/public/legacy/upload

And that the file is permissible to be viewed from a public users perspective (perms 0664)

Hello. Thanks for answering. Apparently it’s not working. When trying the urls I get a blank page and there is no file with the name of the id in the public/legacy/upload location

I have updated the question with more information.

It is quite possible that this is the first time anyone is even considering this bit of functionality for v8.

If I were you, I would get into the code with a debugger and see what’s going on. It might be a good idea to do that first with a working v7, and only afterwards try it in v8 to see the differences.

Hello. Thanks for answering. In a custom module where can I debug the save action? To try to identify what is happening with the value of the file

If you give me the exact URL that is called when saving, I can try finding out where it’s implemented.

You can get the URL at the moment of the save from the browser’s developer tools, network tab.

When the form is submitted I get 2 POST requests

POST http://mycrm.local/api/graphql

If it’s a graphql request, it’s not a request belonging to the legacy view.

Almost, you need to find the distinctive request that happens in save. Not the genetic requests regarding favorites, trackers, these happen in all views.