cancel
Showing results for 
Search instead for 
Did you mean: 

How to upload user avatar images to Alfresco Share?

ofnavarro
Champ in-the-making
Champ in-the-making
Hi,

we are using the RESTFul Api Function "/alfresco/service/slingshot/profile/uploadavatar" to upload user profile images but they are not shown in Alfresco share.

How can we make to create the thumbnail like does the user account edit screen in Alfresco Share?

This is the code used for that:


File file = new File("c:/Prueba.png");

urlResourceAlfresco = "http://" + alfrescoServer + ":" + alfrescoPort + "/alfresco/service/slingshot/profile/uploadavatar";
log.debug("Url Alfresco resource: " + urlResourceAlfresco);
         
FormDataMultiPart form = new FormDataMultiPart();
form.field("username", userName);
form.field("filename", "Prueba.png");
form.bodyPart(new FileDataBodyPart("filedata", file, MediaType.MULTIPART_FORM_DATA_TYPE));
webResource = client.resource(urlResourceAlfresco);
ClientResponse responseAvatar = webResource.type(MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);


It´s working fine uploading the image and updating the user account data but the urls that appears in the property "avatar" links to an avatar thumbnail that it is no automatically created with the "uploadavatar" function.


{
   "url": "\/alfresco\/service\/api\/person\/aaa1",
   "userName": "aaa1",
   "enabled": true,
   "avatar": "api\/node\/workspace\/SpacesStore\/8d3ea206-5bf6-43e8-89be-9ecf9d026f8b\/content\/thumbnails\/avatar",
   "firstName": "Nombre pruebas1",
   "lastName": "Apellidos Pruebas 1",
   "jobtitle": "Puesto de trabajo",…
}


In Alfresco Explorer, user image avatar is correctly showed in details user screen.
1 REPLY 1

ofnavarro
Champ in-the-making
Champ in-the-making
Hi,

after many tests we have located the problem:
MediaType of the "filedata" field on the form was wrong. This field must be of type MediaType.APPLICATION_OCTET_STREAM_TYPE:

<java>
FormDataMultiPart FormDataMultiPart form = new ();
form.field ("username", userName);
form.field ("filename", "test.png");
form.bodyPart (new FileDataBodyPart ("filedata" file, MediaType.APPLICATION_OCTET_STREAM_TYPE));
client.resource = WebResource (urlResourceAlfresco);
ClientResponse responseAvatar = webResource.type (MediaType.MULTIPART_FORM_DATA) .post (ClientResponse.class, form);
</java>

Thumbnail is automatically created when you call to get that image:

…/alfresco/api/service/node/workspace/SpacesStore/39409759-65b9-49bd-a8b3-37fcbe3b6dc7/content/thumbnails/avatar?c=force

Solved.