sys_attachment without the right content_type info

Yonix
Tera Contributor

When the user submits a form in the mobile app with some attachments, the records created in the table sys_attachment do not contain the right info the the field content_type. It is image/* instead of image/jpeg or image/png.
In the mobile app the user can see the image but in the WEB the user receive an error "The file type is currently not supported". (see image Filetype_is_not_supported.png)

Process - How to upload image?
1) Mobile App Builder > Functions We have Action Item that executes following Script:

(function WriteBackAction(parm_input, parm_variable, actionResult) {
        new x_cx1_sar.mobileMain().proccedModule(parm_input, parm_variable, actionResult, 3);
})(parm_input, parm_variable, actionResult);

This Script calls a function in a Script Includes:
proccedModule: function(parm_input, parm_variable, actionResult, module_num) {
        //prepare update set
        var filteredInputs = {
                "fields": [],
                "attachments": []
            },
            module = module_num;

        //is first update
        if (parm_variable.status_module == "false")
            filteredInputs.fields.push({
                "key": "status_module_" + module,
                "value": true
            });
       
        //if in module 7 "extension not needed", set module 8 to completed
        if (parm_input.bep_extension == "extension_not_needed")
            filteredInputs.fields.push({
                "key": "status_module_8",
                "value": true
            });    

        for (var input in parm_input) {
            if (parm_input[input] != "undefined") {
                if (input.indexOf("picture") == -1) {
                    filteredInputs.fields.push({
                        "key": input,
                        "value": parm_input[input]
                    });
                } else {
                    filteredInputs.attachments.push(input);
                }
            }
        }
       
        //gs.info("DRA: " + parm_input.bep_extension);
        //gs.info("DRA: " + global.JSON.stringify(filteredInputs));

        //proceed update set
        var now_GR = new GlideRecord('x_cx1_sar_location');
        if (now_GR.get(parm_variable.cp_id)) {
            filteredInputs.fields.forEach(function(el) {
                now_GR.setValue(el.key, el.value);
            });
            now_GR.update();

            //proceed attachments
            filteredInputs.attachments.forEach(function(el) {

                //check for existing record
                var sysId,
                    name = "md_" + module + "_" + el,
                    existingAttachment = new GlideRecord("x_cx1_sar_mobile_attachments");
                existingAttachment.addQuery("ordezr", parm_variable.sys_id);
                existingAttachment.addQuery("name", name);
                existingAttachment.setLimit(1);
                existingAttachment.query();
                if (existingAttachment.next()) {
                    sysId = existingAttachment.getValue("sys_id");
                } else {

                    //else create new
                    var newAttachment = new GlideRecord("x_cx1_sar_mobile_attachments");
                    newAttachment.initialize();
                    newAttachment.name = name;
                    newAttachment.order = parm_variable.sys_id;
                    sysId = newAttachment.insert();
                }
               
                actionResult.addAttachment(el, "x_cx1_sar_mobile_attachments", sysId);
            });

        }
    },
This function creates a new record "x_cx1_sar_mobile_attachments" with a field name that contains a specific name of the mobile attachment and from which module was uploaded. (see x_cx1_sar_mobile_attachments.png)


I have 2 questions or issues?
1) What is doing the function "actionResult.addAttachment(el, "x_cx1_sar_mobile_attachments", sysId);
"? It is creating the sys_attachment record?
2) I would like to know if there is any way how to set the content_type of the sys_attachment when it is uploaded?

Thanks


 

0 REPLIES 0