mark
mark

Reputation: 959

Alfresco REST, file upload: cannot set description and filename

I'm using the following code to upload a file onto Alfresco

CloseableHttpClient client=HttpClients.createDefault();
    HttpPost postMethod=new HttpPost(AlfrescoRequests.getUploadRequest()+"?alf_ticket="+DocumentUno.alFrescoSessionTicket.replace("\"", ""));
    System.out.println(AlfrescoRequests.getUploadRequest()+"?ticket="+DocumentUno.alFrescoSessionTicket.replace("\"", ""));
    MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.RFC6532);

    reqEntity.addPart("filedata", new FileBody(file));

    reqEntity.addPart("alt_destination",new StringBody("workspace://SpacesStore/9a37fce5-2715-4730-a245-64f161304879"));
    reqEntity.addPart("filename",new StringBody("ip_VM1985.txt"));

    reqEntity.addPart("description", new StringBody("Descrizione del file"));

    postMethod.setEntity(reqEntity);

    System.out.println("executing request " + postMethod.getRequestLine());
    CloseableHttpResponse resp = client.execute(postMethod);

Where AlfrescoRequests.getUploadRequest() gives the REST request URL (query-part excluded)

public static String getUploadRequest()
{
    return DocumentUno.ECM_ADDRESS+"/alfresco/service/api/upload";
}

The upload is done correctly, i get a code 200, but the description is not set and i cannot specify a filename, that remains the same of the original file. Please tell me if you need other details.

Upvotes: 0

Views: 990

Answers (1)

softwareloop
softwareloop

Reputation: 383

The /alfresco/service/api/upload webscript unfortunately does not handle metadata. This is a known feature of Alfresco. The filename is handled but the description, which really is the cm:description property, like any other additional standard or custom properties that you might have, are not saved.

I believe the description parameter of the webscript is used as the first parameter for this API:

ScriptNode checkin(String history, boolean majorVersion)

... and has nothing to do with the document title/description.

There is an open-source plugin (which I authored) that overcomes this limitation by allowing to specify any additional metadata during the upload: http://softwareloop.com/uploader-plus-an-alfresco-uploader-that-prompts-for-metadata/

It comprises a repo amp and a share amp. Since you're using web services, you just need the repo amp.

Upvotes: 1

Related Questions