Upload file from RestApi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2009 09:35 AM
POST /alfresco/service/sample/upload (http://wiki.alfresco.com/wiki/2.1_REST_API#File_Upload_Sample)
for uploading file into alfresco repository. I am using Alfresco Lab 3
How can I use this through HttpClient.
Code I m using is :
String URL = "http://localhost:8080/alfresco/service/sample/upload";
PostMethod post = new PostMethod(URL);
NameValuePair[] data = {new NameValuePair("filename", "C:/testFile.txt"),
new NameValuePair("mimetype", "text/plain"),
new NameValuePair("containerId", "7018a7e3-d366-4389-84c6-bd79d793c270")}; //Company Homes' Id
post.setRequestBody(data);
int statusCode1 = client.executeMethod(post);
The error I am getting is :
"message" : "Failed to execute script '\/org\/alfresco\/upload.post.js (in classpath store file


"org.mozilla.javascript.EcmaError: ReferenceError: \"formdata\" is not defined. (AlfrescoScript#21)"
I will be very thankful if anyone would give me example through sample code.
Regards.
DJ
- Labels:
-
Archive
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2009 10:11 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2009 06:34 AM
Please if anyone can help? + I'm not doing these customization using Alfresco explorer. Because i don't know fully in front-end where to do these customizations. I followed Company_Home > Data_Dictionary > Web Client Extension …
I don't know how to create these files in it?
I just made these files and pasted in
"jboss-4.2.3.GA\server\default\tmp\deploy\tmp28186alfresco-exp.war\WEB-INF\classes\alfresco\webscripts" dir. Other applications i practiced worked fine but this is not working.
PLEASE HELP AS SOON AS POSSIBLE!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2009 07:43 AM
PLEASE HELP AS SOON AS POSSIBLE!You're going to have to supply more information, such as the code you've put together to upload a file with.
Mike

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2009 11:25 PM
im using .js file n code in it im using is here below
for each (field in formdata.fields) {
if (field.name == "name") {
model.name = field.value;
}
if (field.name == "file" && field.isFile) {
filename = field.filename;
content = field.content;
mimetype = field.mimetype;
}
}
var results = search.luceneSearch("+PATH:\"app:company_home/*\" +TYPE:\"cm:folder\" +@cm\\:name:\"Someco\"");
var targetFolder = results[0];
var newDoc = targetFolder.createFile(filename); newDoc.properties.content.write(content); newDoc.properties.content.mimetype = mimetype;
newDoc.save();
here above formdata is being used.
it also gives somtimes error that this targetfolder is undefined. I don't know what built in functions are using because im just following Developer guide book as practise for customization. And path "+PATH:\"app:company_home/*\" +TYPE:\"cm:folder\" +@cm\\:name:\"Someco\" i don't know about it much either If you can please help me?
Other freemarker template file codes are below here…
helloworld.get.html.ftl
<html>
<body>
<form action="${url.service}" method="post" enctype="multipart/
form-data" accept-charset="utf-8">
Name:<input name="name"><br />
File:<input type="file" name="file"><br />
<input type="submit" name="submit" value="Go!">
</form>
</body>
</html>
helloworld.post.html.ftl
<html>
<body>
<p>Hello, ${args.name}!</p>
</body>
</html>
other two files are desc.xml files "helloworld.get.desc.xml" , "helloworld.post.desc.xml".
In post authentication is required but not in get. rest is same.
<webscript>
<shortname>Hello World Form Post</shortname>
<description>Hello world form post web script</description>
<url>/someco/helloworldform</url>
<authentication>admin</authentication>
<transaction>required</transaction>
</webscript>

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2009 12:10 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2009 03:04 AM
it also gives somtimes error that this targetfolder is undefined. I don't know what built in functions are using because im just following Developer guide book as practise for customization. And path "+PATH:\"app:company_home/*\" +TYPE:\"cm:folder\" +@cm\\:name:\"Someco\" i don't know about it much either If you can please help me?If it sometimes gets to the line where the Lucene query is running, then the formdata object must have been parsed correctly in that instance. You need to make sure you've got the "Someco" folder immediately under Company Home.
Mike

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2009 05:26 AM
Mike
Yes you are right there is no Someco folder and i don't know how to make this folder.
Yesterday I practiced wiki example for file uploading
"http://wiki.alfresco.com/wiki/Web_Scripts_Examples#File_Upload"
It has little different code its working perfectly.
But I would like to know as asked before .. "developer guide book" gives error "formdata is undefined". This issue is not resolved.
for each (field in formdata.fields) {
if (field.name == "name") {
model.name = field.value;
}
if (field.name == "file" && field.isFile) {
filename = field.filename;
content = field.content;
mimetype = field.mimetype;
}
}
var results = search.luceneSearch("+PATH:\"app:company_home/*\" +TYPE:\"cm:folder\" +@cm\\:name:\"Someco\"");
var targetFolder = results[0];
var newDoc = targetFolder.createFile(filename); newDoc.properties.content.write(content); newDoc.properties.content.mimetype = mimetype;
newDoc.save();
Can you please tell this?
…………….
[size=150]
And I strongly request you to see my Other post with name "HELP: alfresco APIs and Services? "
[/size]
PLEASE I'LL BE VERY VERY THANKFUL TO YOU! I want to complete it as soon as possible.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2010 07:21 AM
I have uploaded with this sample html. hope this helps in uploading a file
<html><head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/> <title>File Upload</title> </head><body> <form method="POST" name="uploadForm" enctype='multipart/form-data' id="upload_form" action="http://localhost/alfresco/service/api/upload"> <input type="hidden" name="destination" id="destination" value="workspace://SpacesStore/9305eefb-d062-45de-b135-4c7a505b89ba"/> // node reference of the folder where you want to upload , you can get it from alfresco webclient by view details action <label> Name: </label> <br/> <input type="text" name="filename" id="filename"/><p/> <label> Description: </label> <br/> <textarea name="description" id="description"></textarea> <p/> <label> File: </label> <br/> <input class="button" type="file" name="filedata" id="filedata"/><p/> <input class="button" type="submit" name="submit" value="Upload"/> </form></body></html>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2010 10:43 AM
