Alfresco/alfresco-js-api

getNodeContent throwing error

psedwards99 opened this issue · 12 comments

Type of issue: (check with "[x]")

- [ ] New feature request
- [x ] Bug  
- [ ] Support request

Current behavior:

Running this.nodesApi.getNodeContent(nodeId, opts) throws an error:

Type Error: Value is not a sequence: alfrescoApiClient.js:174

If I view the HTTP trace (via the browser developer tools), the REST call can be seen to return correctly, but the API fails before it can return the file back to my code.

My code is an angular 10 application. alfresco-js-api was installed via npm and each of my components I use:

include {AlfrescoApi, NodesApi} from '@alfresco/js-api';

Expected behavior:

getNodeContent should return the content as blob

Steps to reproduce the issue:

Run getNodeContent as above.

Node version (for build issues):

Angular 10.1.7
Node 12.16.1
NPM 6.14.8
Alfresco repository 6.2.2 (Enterprise)
alfresco-js-api 4.1.0

alfresco-js-api 4.2.0 - issue is still there. Content shouldn't be text to reproduce. XLSX, DOCX, images - good scenarios to reproduce.

If I understood correctly, the fix should be in the file nodes.api.ts, line 856:
contentTypes, accepts , Blob);
to
contentTypes, accepts ,'blob');

Until the fix, the workaround could be manual call to callApi method:

nodeApi.apiClient.callApi(
        '/nodes/{nodeId}/content', 'GET',
        pathParams, queryParams, headerParams, formParams, postBody,
        contentTypes, accepts, 'blob');

Fill arguments like here:

getNodeContent(nodeId: string, opts?: any): Promise<Blob> {

garth commented

is this error related?

/usr/src/app/node_modules/@alfresco/js-api/src/alfrescoApiClient.js:172

data = new Blob([data], { type: response.header['content-type'] });


ReferenceError: Blob is not defined
 at ContentClient.deserialize (/usr/src/app/node_modules/@alfresco/js-api/src/alfrescoApiClient.
js:172:17)
 at /usr/src/app/node_modules/@alfresco/js-api/src/alfrescoApiClient.js:264:37

Blob is not available in node, it should probably be using an array buffer or some polyfill?

dhrn commented

what is your js-api version?

garth commented

what is your js-api version?

4.4.0-beta18

dhrn commented

seems you are using latest beta. can you tell me how to reproduce the above problem?

garth commented

The error is thrown whenever you call getNodeContent() which is why I thought it might be related to this issue.

nodesApi.getNodeContent(entry.id)
node --version
v15.14.0

tsc --version
Version 4.2.4
garth commented

It seem that since node 15.7 there is an experimental Blob implementation.

Adding the following code fixes the error:

import buffer from 'buffer'

// @ts-ignore
global.Blob = buffer.Blob

But since this is an experimental feature and not supported in earlier versions of node it should probably not be depended upon for production builds.

@garth can you try the version in this branch #1084 ?

garth commented

It looks like that branch got merged overnight, so I've tested with 4.4.0-3443 this morning, but the problem is not fixed.

Looking at the build output, the js and ts files are still in the same folder. I don't think the problem will be fixed until they are separated.

@garth if we talk about the getNodeContent there is also an example working now in https://github.com/Alfresco/alfresco-js-api/blob/develop/test/integration/test-node/node-content.ts if you have the problem with the types that was a separate PR that got merged yesterday so you can try it as well now

Solved in ADF 4.4.0