Hi Gyro,
Thanks for you response.
Actually, I wrote a script for file uploading based on the example. I paste the code below:
BTW, I call this script in another .net application. Before file uploading, the .net app calls the authenticaiton script to get the ticket and the appends the ticket string to the uploading url. Only the first time, end users need to input the username & password in the popup dialog. But I don't want them to do this even only one time.
upload.post.desc.xml
<webscript>
<shortname>File Upload Sample</shortname>
<description>Upload file content and meta-data into Repository</description>
<url>/sample/upload</url>
<authentication>user</authentication>
</webscript>
upload.post.js
var filename=null;
var content=null;
var title="";
var description="";
var uploadpath="";
var scajxh;
var scbgqx;
var scflbm;
var schgzh;
var schth;
var scjhao;
var scmiji;
var scqzh;
// locate file attributes
var field;
for each (field in formdata.fields)
{
if (field.name=="title")
{
title=field.value;
}
else if (field.name=="desc")
{
description=field.value;
}
else if (field.name=="file" && field.isFile)
{
filename=field.filename;
content=field.content;
}
else if (field.name=="uploadpath")
{
uploadpath = field.value;
}
else if (field.name=="scajxh")
{
scajxh = field.value;
}
else if (field.name=="scbgqx")
{
scbgqx = field.value;
}
else if (field.name=="scflbm")
{
scflbm = field.value;
}
else if (field.name=="schgzh")
{
schgzh = field.value;
}
else if (field.name=="schth")
{
schth = field.value;
}
else if (field.name=="scjhao")
{
scjhao = field.value;
}
else if (field.name=="scmiji")
{
scmiji = field.value;
}
else if (field.name=="scqzh")
{
scqzh = field.value;
}
}
// ensure mandatory file attributes have been located
if (filename==undefined || content == undefined)
{
status.code = 400;
status.message = "Uploaded file cannot be located in request";
status.redirect = true;
}
else
{
// create document in company home for uploaded file
if (uploadpath==null||uploadpath==undefined||uploadpath==""){
//upload = companyhome.createFile(filename) ;
upload = companyhome.createNode(filename,"sc:equipment");
}
else {
upload = companyhome.childByNamePath(uploadpath).createNode(filename,"sc:equipment") ;
}
upload.properties.content.write(content);
upload.properties.encoding = "UTF-8";
upload.properties.title = title;
upload.properties.description = description;
if (scajxh!=null&&scajxh!=undefined&&scajxh!=""){
upload.properties["sc:ajxh"]=scajxh;
}
if (scbgqx!=null&&scbgqx!=undefined&&scbgqx!=""){
upload.properties["sc:bgqx"]=new Date(scbgqx);
}
if (scflbm!=null&&scflbm!=undefined&&scflbm!=""){
upload.properties["sc:flbm"]=scflbm;
}
if (schgzh!=null&&schgzh!=undefined&&schgzh!=""){
upload.properties["sc:hgzh"]=schgzh;
}
if (schth!=null&&schth!=undefined&&schth!=""){
upload.properties["sc:schth"]=schth;
}
if (scjhao!=null&&scjhao!=undefined&&scjhao!=""){
upload.properties["sc:jhao"]=scjhao;
}
if (scmiji!=null&&scmiji!=undefined&&scmiji!=""){
upload.properties["sc:miji"]=scmiji;
}
if (scqzh!=null&&scqzh!=undefined&&scqzh!=""){
upload.properties["sc:qzh"]=scqzh;
}
upload.save();
// setup model for response template
model.upload = upload;
}