Free Support Forum - aspose.cloud

Can aspose words cloud node SDK handle streams as input?


#1

Aspose words cloud node SDK putconvertdocument method, can’t find documentation or examples anywhere.
Can the putconvertdocument method hand file streams as input?
I can save temp files locally and read from my local file system but this is an unnecessary step if putconvertdocument can handle a file stream as input


#2

@rfdesouza

Aspose.Words offer three REST APIs to convert a document to another format:

GET /words/{name}
PUT /words/convert
POST /words/{name}/saveAs

In PUT /words/convert API we pass the input document in the request body whereas in case of GET /words/{name} and POST /words/{name}/saveAs APIs we first upload document to Cloud Storage (using Aspose.Storage Upload API) and pass input document name as an argument to the API.

We will shortly share with you complete Node.js example of PUT /words/convert API.


#3

Okay I have read about your rest APIs, my question is specifically about the SDK for node.

Can the putconvertdocument method handle streams as input?


#4

@rfdesouza

Following is the example of putConvertDocument method of Aspose.Words Node.js SDK:

describe("putConvertDocument function", () => {
            /**
             * Test runner
             * @param value destination fromat
             */
            function runner(value) {
                const request = new PutConvertDocumentRequest({
                    format: value,
                    document: fs.readFileSync(localPath),
                });

                // Act
                return wordsApi.putConvertDocument(request)
                    .then((result) => {
                        // Assert                
                        expect(result.response.statusCode).to.equal(200);
                        expect(result.body.byteLength).to.greaterThan(0);
                    });
            }

            testWithTestCases({
                name: "convert from 'docx' to {value} should return response with code 200",
                values: BaseTest.saveFormatTestCases,
                runner,
            });           
});

If we particularly focus on PutConvertDocumentRequest object you may observe that fs.readFileSync method is taking the file path as input and returns a buffer.

const request = new PutConvertDocumentRequest({
    format: value,
    document: fs.readFileSync(localPath),
});

Following directory contains the Unit Tests (examples) of each Node.js SDK API:

The Unit Tests are grouped by the type of action over the document. Action could be one of two types: we can somehow change document elements, e.g. borders, fields etc. or we can make some document actions e.g. convert, mailmerge and so on.