cancel
Showing results for 
Search instead for 
Did you mean: 

Uploading files using RESTful

elimarcos
Champ in-the-making
Champ in-the-making
Hi,

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.
18 REPLIES 18

pyt
Champ on-the-rise
Champ on-the-rise
What API do you recommend?

I want to create a folder in PHP.

iblanco
Confirmed Champ
Confirmed Champ
Sorry, I thought you were using the same API as Elimacros. The API you are trying to use seems to me that should be the right one but after glancing over it seems to me that it might only support CMIS requests, not JSON requests.

So you can make your own API or just use the FormProcessor API as Share does.

pyt
Champ on-the-rise
Champ on-the-rise
Hey,

I've changed now to RESTful API.

I'd like to upload my files with REST API, but now I'm facing an other problem.
This is my URL:

http://localhost:8080/alfresco/service/api/upload


An this is my PHP code:

$json = ('
        {
            "filename":"HAHA.PDF",
            "destination":"workspace://SpacesStore/'.$parentID.'",
            "filedata":"'.$file.'"
        }
    ');
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_HTTPHEADER, Array("Content-Type: application/json"));
    curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC) ;
    curl_setopt($curl, CURLOPT_USERPWD, "admin:admin");
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_URL, $submit_url);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $json);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

    $rs = curl_exec($curl);


Every time i execute my script, i receive an Error -> Error 500

best regards
pyt

aleksczajka
Champ in-the-making
Champ in-the-making
pyt, did you finally get the answer to your question? I'm at the beginning of the process of attempting to upload images to Alfresco using xml files from the client. I'm also using PHP. What ended up working for you?

kisanme
Champ in-the-making
Champ in-the-making
Request type should be multipart/formdata as far as the webscript for the upload api is concerned.

I'm also still struggling to crack this issue, if you have already found how to do this in PHP, can you please mention that?

koopa
Confirmed Champ
Confirmed Champ
I'm using RESTful API. Can I use
siteid
,
containerid
,
uploaddirectory
to upload a file to a specific site directory inside
documentLibrary
? It does not work… These are the values I use:

siteid = "repo",
containerid = "documentLibrary",
uploaddirectory = "raps"

The files upload succesfully but it ignores the
uploaddirectory
param so I find them under
repo/documentLibrary
instead of
repo/documentLibrary/raps
.
Is it my fault? I don't use
destination
param.

koopa
Confirmed Champ
Confirmed Champ
I really don't know why but I found that to upload to a specific directory I have to give the uploaddirectory parameter with '/' at first and last char of the string. I mean:
<ol>
<li>"dir" won't work</li>
<li>"/dir" won't work</li>
<li>"dir/" won't work</li>
<li>"/dir/" works!</li>
</ol>

shinu
Champ in-the-making
Champ in-the-making
Hi
i am new to this tool.I am using restful api for uploading files.By using noderef i can upload files.Is it anyway upload files by folder name
In our application I have folder like Testing under testing, i have sub folder like test 1 ,test 2 etc.this test1 and test2 generated in alfresco whenever user register application by using alfresco rest api.By looking node ref and nodeid everytime is not good deal.Could you pleaee provide any feasible solution with sample code for uploading and downloading

domenico
Champ in-the-making
Champ in-the-making
Hi there,
I'm try to upload a file to the shared folder…
This is my code.
<java>
    // using httpclient-4.5
   
    Path filePath = Paths.get("C:/afile.txt");
    String ticket = getTicket();  //  get a ticket via /alfresco/service/api/login…

    CloseableHttpClient client = HttpClients.createDefault();
    HttpPost post = new HttpPost("http://localhost:8080/alfresco/service/api/upload?alf_ticket=" + ticket);
    MultipartEntityBuilder entity = MultipartEntityBuilder.create();
   
    StringBody descriptionBody = new StringBody("a test", ContentType.TEXT_PLAIN);
    StringBody siteId = new StringBody("company_home", ContentType.TEXT_PLAIN);    //  how can upload the file
    StringBody containerid = new StringBody("/Shared", ContentType.TEXT_PLAIN);    //  in the shared folder??

    entity.addBinaryBody("filedata", filePath.toFile());
    entity.addPart("siteid", siteId);
    entity.addPart("containerid", containerid);

    post.setEntity(entity.build());
      
    CloseableHttpResponse postResponse = client.execute(post);
   
   // …
</java>

Can anyone help me? Thanks.