Uploading files using RESTful
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2013 09:27 AM
I am using the following approach to perform uploading files to the Alfresco repository:
URL: http://localhost:8080/alfresco/service/api/upload/?alf_ticket = {User's ticket}parameters: [filedata, filename, description, siteid, containerId]
However, this approach does not allow me to insert files in specific subdirectories.
I need to perform file uploads via RESTful api using the uuid of the target folder.
Does anyone have any tips how to do this?
Alfresco Version: 4.2.c
ps. Sorry for my english!
Grateful.
- Labels:
-
Archive
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2013 11:45 PM
URL: http://localhost:8080/alfresco/service/api/upload/?alf_ticket = {User's ticket}File file = new File("C:/Test_Upload.pdf");String filetype = "application/pdf"String filename="Test_Upload.pdf";HttpClient client = new HttpClient();PostMethod post = new PostMethod(URL);Part[] parts = { new FilePart("filedata", filename, file, filetype, null), new StringPart("filename", filename), new StringPart("description", "description"), new StringPart("siteid", "yoursite"), new StringPart("containerid", "documentLibrary"), // your can add more paramter here //new StringPart("uploaddirectory", "documentLibrary"), //new StringPart("updatenoderef", "updatenoderef"), //new StringPart("contenttype", "contenttype"), //new StringPart("aspects", "aspects") ….. };post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));int status = client.executeMethod(post);System.out.println(post.getResponseBodyAsString());post.releaseConnection();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2014 12:36 PM
how you are managing your upload file code. The java script restricts "transaction required". First But your code is without Transaction.
second, I managed to add transaction but not succeeded..Can you tel me some way to do that.
try
{
userTransaction1.begin();
post.setRequestEntity(new MultipartRequestEntity(parts, post
.getParams()));
int status = client.executeMethod(post);
System.out.println(post.getResponseBodyAsString());
post.releaseConnection();
userTransaction1.commit();
}
catch(Exception e)
{
try { userTransaction1.rollback(); } catch (IllegalStateException ee) {}
throw e;
}
Can you answer how you manage it without transaction ??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2013 09:00 AM
Inspecting the POST with Chrome's developer tools I see that this API gets a "destination" parameter with the NodeReference of the destination folder, so if you can get the NodeRef of your destination folder you should be able to send content there.
Furthermore, if you check this API's documentation (http://localhost:8080/alfresco/service/script/org/alfresco/repository/upload/upload.post) it seems like it should even be able to accept and "uploadDirectory" parameter that refers to a destination folder by path name.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2013 09:02 AM
http://wiki.alfresco.com/wiki/Web_Scripts_Examples#File_Upload
With this as an example you could even build your own webscript for upload and implement the logic you prefer to decide where to put the content.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2013 09:30 AM
Anyway, I could understand what I was doing wrong!
Using the example of kaynezhang and checking API suggested by iblanco, I found that the parameter "siteid" deletes the parameter "destination".
I was trying to use both, so it was not working. It was just remove the "siteid" that the parameter "destination" started to function as it should.
Part[] parts = { new FilePart("filedata", filename, file, filetype, null), new StringPart("filename", filename), new StringPart("description", "description"), // new StringPart("siteid", "yoursite"), // new StringPart("containerid", "documentLibrary"), new StringPart("destination", "workspace://SpacesStore/7118e242-86b1-489a-ac2e-193364ccf6e4"),}
Thank you for everything!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2014 12:38 PM
In your code you mentioned new StringPart("destination", "workspace://SpacesStore/7118e242-86b1-489a-ac2e-193364ccf6e4")
I am not able to get the destination value, how to get it???
your detailed explanation can really help?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2013 12:40 PM
If siteId is null, upload webscript works in non site mode.the content will be upload in a destination node specified by destination parameter.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2013 05:57 AM
i'd like to create a folder via RESTful API. Is it in anyway possible, to use the code that kaynezhang wrote to create a document for my case?
What I am actually trying to do is to create a folder using the "DEV HTTP CLIENT" in chrome browser.
These are my inputs:
URL:
POST localhost:8080/alfresco/service/api/node/workspace/SpacesStore/15fc9618-56a5-4037-ac25-508899d5ba28/children
These are the parameters i send with:
{"alf_destination":"workspace://SpacesStore/15fc9618-56a5-4037-ac25-508899d5ba28","prop_cm_name":"test","prop_cm_title":"","prop_cm_description":""}
Every time i send the request, i recive a response saying: 400 Bad Request
What do I have to change?
Best regards
pyt
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2013 06:19 AM
Share creates folder by calling the form processor: http://localhost:8080/alfresco/service/api/type/cm%3afolder/formprocessor
And POST somethin like:
{"alf_destination":"workspace://SpacesStore/90c7ba28-b991-48db-8ba3-f42a198dd54e","prop_cm_name":"MyFolder","prop_cm_title":"","prop_cm_description":""}
There might be a better API to do this, but this should also work.
