Hello, I need some help to resolve my problem, I have a dashlet for sending files like images. I need to transfer data to alfresco webscript so I use an ajax request, the problem is : I can't write my image content to the new createFile I have created, I tried to use : newFile.properties.content.write(filecontent); but "method write is not found" ???
<#——————————————————————————————————-> function loadImageFile() { if(document.getElementById('${args.htmlid}-images').files.length === 0) {return; } var files = document.getElementById('${args.htmlid}-images').files.item(0); if(!files.type.match(filter)) { alert("Choose another image !"); return; } reader.readAsDataURL(files); }
<#——————————————————————————————————->
function generateForm() {
var title = new YAHOO.util.Element('${args.htmlid}-title').get('value'); var description = new YAHOO.util.Element('${args.htmlid}-description').get('value'); var category = new YAHOO.util.Element('${args.htmlid}-category').get('value');
var files = document.getElementById('${args.htmlid}-images').files; if(files) { for (var i = 0; i < files.length; i++){ files_v = files; files_v['content'] = document.getElementById('uploadPreview').src; } }
var data = { "fields": [ { title : title, description : description, category : category, files: files_v } ] };
my model : customAlfresco.xml <javascript> <?xml version="1.0" encoding="UTF-8"?> <!– Definition of new Model –> <model name="ca:customAlfresco" xmlns="http://www.alfresco.org/model/dictionary/1.0"> <!– Optional meta-data about the model –> <description>Alfresco's Customization</description> <version>1.0</version> <!– Imports are required to allow references to definitions in other models –> <imports> <!– Import Alfresco Dictionary Definitions –> <import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d" /><!– d = Dictionary Model –> <!– Import Alfresco Content Domain Model Definitions –> <import uri="http://www.alfresco.org/model/content/1.0" prefix="cm" /><!– cm = Content Model –> </imports>
<!– Introduction of new namespaces defined by this model –> <namespaces> <namespace uri="org.obs.custom-alfresco.model" prefix="ca" /><!– ca = prefix of my custom model –> </namespaces>
Thank you Jeff for your reply ! Yes the document is created but the uploaded image won't be displayed and It's seems damaged. I think I have to use multipart content type to transfer my data with submit button, but It's hard to do it from a dashlet to an alfresco webscript. How can I define my action form if my descriptor webscript file url is : /api/form/add-news ??? Thanks & regards
Your form action URL can leverage the Share proxy URL. That way, your form can post to Share and Share will forward the post on to the repository tier. If you do a recursive grep on $TOMCAT_HOME/webapps/share/WEB-INF/classes/alfresco/site-webscripts you'll find lots of examples of that.