Search code examples
wakanda

Uploading an image for an entity attribute in Wakanda Server


I am attempting to upload an image from a file on the client as the value of a Wakanda entity's image attribute named thumbnail. I am using the example from the documentation but I'm getting the following error in the browser:

Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:8081/Artwork(016A8CCE202847FA87DF78A27353121D)/thumbnail?$rawPict=image/jpeg

Here is my code:

ds.Artwork.find(artworkId).then(artwork => {
    return artwork.thumbnail.upload(this.testFileInputElement.files[0]);
}).catch(e => {
    debugger;
});

The error is returned in the catch e argument. I have checked that the artwork entity is retrieved properly, the thumbnail attribute has an upload method and that this.testFileInputElement.files[0] is a proper File object.


Solution

  • 2nd Update: The bug is fixed in latest version of Wakanda.

    Update: I filed a bug on Wakanda Github and it has been accepted. You can track the bug status there. In the meantime, please feel free to use the workaround provided below.

    I tested and get the same 404 error. This appears to be a bug. The correct file upload URL should have "/rest" between baseURL and dataclass name like: http://localhost:8081/rest/Artwork(016A8CCE202847FA87DF78A27353121D)/thumbnail?$rawPict=image/jpeg.

    The fix I found is to add "/rest" to line 3454 of "wakanda-client.no-primise.js" in web/node_modules/wakanda-client:

    MediaBaseService._buildUri = function (dataClassName, entityKey, attributeName) {
            return '/rest/' + dataClassName + '(' + entityKey + ')' + '/' + attributeName;
    };
    

    This fix worked for me. I will report the bug and potential fix to the team. enter image description here