4

I am trying to send multipart/form-data through URLRequest on my app to Cloud Functions for Firebase. And to test if my cloud function and my app are connected, I created a test function and deployed it:

function test(data, callback) {
    console.log("Test begin:");
    console.log(data);
    console.log("Test finish...");
    callback(null, null);
}

exports.test = functions.https.onRequest((request, respond) => {
    console.log("test called");
    test(request.body.data, function(data, error) {
        respond.json({
            data: data, 
            error: error
        });
    });
});

However, after sending the URLRequest, nothing was printed on the console, and instead, I got a html as data. By opening the html, I get Error: Forbidden. Your client does not have permission to get URL / from this server. How can I fix this?

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
AlexBains
  • 295
  • 6
  • 14

2 Answers2

2

Thanks to @Doug Stevenson, the problem is that I used the wrong URL instead of the provided one. And the URL can be found on the console when you deploy your cloud function.

AlexBains
  • 295
  • 6
  • 14
1

Cloud Functions has special ways of dealing with different types of input. It's documented here.

For multipart/form-data, you can access the content as request.rawBody.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • First of all, thanks for replying. I think the problem is that the cloud function I wrote didn't print anything to the console, in other words, it was never invoked. And it seems like I need to provide something to firebase or i will not be able to send request to it. But still, the link you provide is really helpful. – AlexBains Dec 25 '17 at 03:18
  • Are you using the URL that was printed to the console when you deployed? – Doug Stevenson Dec 25 '17 at 03:19
  • I just tried the URL it provided, and it worked, Thanks a lot. – AlexBains Dec 25 '17 at 03:30
  • 2
    Hi @DougStevenson I got the same problem despite I use a URL which I got from CLI. Don't you happen to know what might it be? Thanks. – Ivan Apr 30 '18 at 23:33