AnsweredAssumed Answered

File upload in create-content of custom content types

Question asked by itzamna on Sep 24, 2013
Hi all,

we're providing an interface to connect Alfresco with another system. Therefore we've a custom content model, but documents of our types are usually created by batch jobs or import jobs not by end-users. For presentation purposes (mainly) and to provide the opportunity to create documents of our custom content types manually in rare cases at all, I was able to customize the share-custom-config.xml in a way that all our properties and aspects for the documents appears. Blank documents are created, so it works in general. But now I need the opportunity to upload a file in the create mask as content for the document. I found already some approaches but none of them matches the requirement:
For example, the content type selection when uploading a file would already fit the needs (even it's not supported yet: http://www.iptech-group.com/blog/alfresco-share-tip-content-type-selection-when-uploading-a-document#.UkHQmz8jT2c) but this does not work on Linux installations, because the dnd-upload will close the popup immediately after uploading the files (without letting the user choose the content type). We can not override this function, as we do not have influence to the customer (and their systems) who will install our provided AMP file.
Also I found the approach with the "submission-url" property in the <form> tag: http://forums.alfresco.com/forum/developer-discussions/alfresco-share-development/file-upload-create-content-06282010-2333. But this seems to be a lot of programming effort, which is not my intention as it should be only a means to end. In general, I think this approach sounds promising but the post is older than 3 years. Maybe with Alfresco 4.2 the requirement can be solved with customizing only? Or at least with a minimum of programming and without to override Alfresco resources?

What is currently the easiest way to provide the creation of documents in Alfresco Share for custom content types with a file upload?

My idea is to extend the share-config-custom.xml like:


<config evaluator="string-compare" condition="DocumentLibrary">
   <create-content>
      <content id="myType" mimetype="text/plain" icon="myTypeIcon" label="myType.createcontent" itemid="myPrefix:myType"/>
   </create-content>
   …


The create form of custom content type (custom types are derived from cm:content):

<config evaluator="model-type" condition="myPrefix:myType">
   <forms>
            <!– http://wiki.alfresco.com/wiki/Web_Scripts_Examples#Upload_Form-->
            <form submission-url="/myApplication/upload">
                <field-visibility>
                    <show id="myPrefix:Property1"/>
                    <show id="myPrefix:Property2"/>
                    <show id="myPrefix:Property3" />
                    <show id="cm:name"/>
                    <show id="cm:content" force="true" />
                </field-visibility>
                <appearance>
                    <set id="basic" appearance="bordered-panel" label-id="basic.create.label" />
                    <set id="my" appearance="bordered-panel" label-id="myType.create.label" />
                    <field id="myPrefix:Property1" set="my"/>
                    <field id="myPrefix:Property2" set="my"/>
                    <field id="myPrefix:Property3" set="my"/>
                    <field id="cm:name" set="basic"/>
                    <field id="cm:content" set="basic" >
                        <control template="/org/alfresco/components/form/controls/fileUpload.ftl" />
                    </field>
                </appearance>
            </form>
            …


Where fileUpload.ftl is (from post above):

<div class="form-field">
    <label for="${fieldHtmlId}">${field.label?html}:<#if field.mandatory><span class="mandatory-indicator">${msg("form.required.fields.marker")}</span></#if></label>
    <input type="file" id="${fieldHtmlId}" name="${field.name}" />
</div>


But I dont know to handle the submission-url. Do I have to save all properties in the form in the webscript behind? At least I only need to hande the file upload as the rest will be done by Alfresco already.


Thanks!

Outcomes