1

I'm trying to upload a file to nanosets API. I uploaded the following node js function to firebase and trying to excess it with following URL for example with a file in body (trying to test this with postman)

Node js function looks like:

    exports.uploadFile = functions.https.onRequest((req, res) => {
    cors(req, res, () => {
        if (req.method !== "POST") {
            return res.status(500).json({
                message: "Not allowed"
            });
        }

        const busboy = new Busboy({headers: req.headers});
        let uploadData = null;

        busboy.on("file", (fieldname, file, filename, encoding, mimetype) => {
            const filepath = path.join(os.tmpdir(), filename);
            uploadData = {modelId: '4bc54977-60cf-4415-a417-c39f1c18b83f', file: fs.createReadStream(filename), type: mimetype};
            const options = {
                url: 'https://app.nanonets.com/api/v2/OCR/Model/XXXXXXX-60cf-4415-a417-c39f1c18b83f/LabelFile/',
                formData: uploadData,
                headers: {
                    'Authorization': 'Basic ' + Buffer.from('tiOJNxuDbdl40lXXXXXXXXXXFTYbY' + ':').toString('base64')
                }
            };

            request.post(options, function (err, httpResponse, body) {
                if (err) {
                    console.log(err);
                }
                console.log(body)
            });


        });
        busboy.on("finish", () => {
            res.status(200).json({
                message: "It worked!"
            });

        });
        busboy.end(req.rawBody);

    });
});

Why I check the logs with firebase functions:log I get the following results:

2020-06-06T09:35:06.168774140Z D uploadFile: Function execution started 2020-06-06T09:35:06.344Z I uploadFile: invoice_4.pdf 2020-06-06T09:35:06.432Z I uploadFile: FileStream { 2020-06-06T09:35:06.439Z E uploadFile: TypeError: source.pause is not a function

Anyone an idea? How to pass the file to nanosets?

1 Answer 1

2

In order to make outgoing requests from Cloud Functions, your project must be on the Blaze payment plan.

Sign up to request clarification or add additional context in comments.

5 Comments

I have the Blaze plan
What happens if you try to request some other URL for a different site or service?
What do you mean?
Instead of app.nanonets.com try something else just to see if it works. If you're actually on a payment plan, you're going to have to do some debugging to figure out what's going wrong here. It's not obvious from what you're showing now.
I got a little bit further, but still have an issue with passing the file to the nanonets API. Any idea?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.