【发布时间】:2018-10-15 09:23:02
【问题描述】:
我是这个领域的新手,我在 2 天前开始使用 firebase 云功能。
对不起,我还是个学生,所以我可能无法清楚地理解一些文档。
我试图弄清楚参数是如何从我的客户端 javascript 传递到 firebase 云函数的。
我的云功能
exports.OCR = functions.https.onCall((req) => {
const vision = require('@google-cloud/vision');
// Creates a client
const client = new vision.ImageAnnotatorClient();
console.log(req);
// Performs label detection on the image file
client
.documentTextDetection(req)
.then((results) => {
console.log("Entered");
console.log(req);
const fullTextAnnotation = results[0].fullTextAnnotation;
console.log(fullTextAnnotation.text);
return results[0].fullTextAnnotation.text;
})
.catch(err => {
console.error('ERROR:', err);
return "error";
});
})
我正在使用 firebase 云功能和 Google Vision API。
其实我是这样尝试传递参数的
我的客户端 coe
document.getElementById("fileInput").click();
var file = document.getElementById("fileInput");
var fileInput = document.getElementById('fileInput');
fileInput.addEventListener('change', function (e) {
var file = e.target.files[0];
// Do something with the image file.
var tmppath = URL.createObjectURL(file);
console.log(file);
console.log(tmppath);
//var url = "https://firebasestorage.googleapis.com/v0/b/recette-f3ef5.appspot.com/o/FB1.gif?alt=media&token=28727220-181c-440e-87ae-4808b5c9ba28";
OCR(file)
.then(function(result) {
console.log(result);
}).catch(function(err) {
console.log(err);
});
});
它没有工作。触发函数时总是返回null。
那么,我的问题是如何将文件(HTML INPUT TAG)传递给我的云函数?
ps:当我尝试使用 node the_code.js 的代码时,它可以工作。
【问题讨论】:
-
如果您正在使用代码,您应该将其直接复制到问题中,以便于阅读和搜索。您可能还想阅读本文以完善您的问题:stackoverflow.com/help/how-to-ask
-
感谢您的建议!我改了! @DougStevenson
标签: javascript html firebase google-cloud-platform google-cloud-functions