Foren

Liferay 6.2 JSONWS update-portrait

thumbnail
Rodrigo Mantica, geändert vor 6 Jahren.

Liferay 6.2 JSONWS update-portrait

New Member Beiträge: 6 Beitrittsdatum: 29.05.17 Neueste Beiträge
Hey everyone, this is my first post on the forums and I have a few questions regarding Liferay 6.2 web API.

I'm trying to figure out how to send image data to liferay via url post requests. I've been testing this functionality with the update-portrait call to update user images. I'm using Angular 4 as the frontend, calling JSONWS to access our backend.

I've tried sending the bytes array as an arrayBuffer, array, binaryString, and base64String but no luck so far. Has anyone successfully used the JSONWS REST API to send image data to liferay? If so, I would really appreciate some help.

Regards,
Rodrigo Mantica

EDIT:

I noticed the file submission part in the docs:

<form action="http://localhost:8080/api/jsonws/dlapp/add-file-entry" method="POST" enctype="multipart/form-data">
    <input type="hidden" name="repositoryId" value="10172">
    <input type="hidden" name="folderId" value="0">
    <input type="hidden" name="title" value="test.jpg">
    <input type="hidden" name="description" value="File upload example">
    <input type="hidden" name="changeLog" value="v1">
    <input type="file" name="file">
    <input type="submit" value="addFileEntry(file)">
</form>


This did not work in my Angular 4 app, but it gave me enough to set this up successfully:

updatePortrait(user, bytes, callback) {
    const self = this;
    var headers = this.headers;
    headers.append('Content-Type', 'text/plain; charset=utf-8');
    headers.append("enctype", "multipart/form-data");
    const endpoint = this.api + "/user/update-portrait.2/userId/" + user.userId;
    var formData = new FormData();
    // formData.append('userId', user.userId);
    formData.append('bytes', bytes);
    this.http.post(endpoint, formData, {headers})
    .map(res =&gt; res.json())
    .subscribe(data =&gt; {
      console.log("updated user portrait:");
      console.log(data);
      callback(data);
    });
  }


After fighting through a couple of exceptions, I'm not stuck at a seemingly trivial one:
"com.liferay.portal.UserPortraitSizeException"


I've updated my portal settings to allow up to 2mb uploads for user portraits. The image I'm trying to upload is 500 x 500 and roughly 90kb. Any ideas?
thumbnail
Andrew Jardine, geändert vor 6 Jahren.

RE: Liferay 6.2 JSONWS update-portrait

Liferay Legend Beiträge: 2416 Beitrittsdatum: 22.12.10 Neueste Beiträge
Hi (again) Rodrigo,

Are you sure that the exception is the result of no file being received on the server? Is there a (java) stacktrace in the server logs at all that you can share? If there is not (sometimes JSONWS exceptions hidden under DEBUG level logging) you can try increasing the log level to expose more details.

In the Control Panel > Server Administration > Log levels choose Add Category and then fill in the values as

[indent]com.liferay.portal.jsonwebservice
ALL[/indent]

Then retry your test and if there are more details in the log, can you share them with us?