ahmader / node-zoho

Zoho API access for NodeJS
21 stars 15 forks source link

Fix broken upload file via body #45

Closed pahan35 closed 6 years ago

pahan35 commented 6 years ago

When I started implement deleteFile I noticed that files attached via attachmentUrl only as direct links image

So when I tried to upload it correctly I need to write code like this

const url = require("url"),
    path = require("path"),
    request = require("request");

const parsed = url.parse(remoteUrl),
    filename = path.basename(parsed.pathname);

request(remoteUrl, (error, res, body) => {
    if (error) return reject(error);

    const zoho = getZoho();
    zoho.execute('crm', module, method, id, body, {filename}, (err, result) => {
        let error;
        if (err !== null) {
            error = err;
        } else if (result.isError()) {
            error = result.message;
        }

        if (error) {
            reject(error);
        } else {
            resolve(result);
        }
    });
});

But in this case I noticed that file don't pass properly, cause body is a string.

So I change check condition in uploadFile and test for this function.

Then I successfully upload my file (first in the list)

ahmader commented 6 years ago

Are you testing with the real API?

Because without integration tests we cannot make sure this work. However I can merge if you are testing live and later we will do the integration test.

pahan35 commented 6 years ago

This is tested with real API.

Tests are in actual state cause there is no new breaking changes.

Only my logic for uploading via attachmentUrl changed a bit to run if missed descriptor param.