手書きのテキストドキュメントにGoogleVision APIとFirebaseクラウド関数を使用していて、Firestoreに保存しています。
ここで「画像内の手書きを検出する」ガイドに従っています:https://cloud.google.com/vision/docs/handwriting#detect_document_text_in_a_remote_image
私が抱えている問題は、テキストペイロードをfirestoreに保存できないように見えることです。クラウドログでデータが通過しているのを確認できますが、エラーが発生します。
imageTagger.js
クラウド機能:
この関数のエラーエラー:引数「data」の値は有効なFirestoreドキュメントではありません。入力は単純なJavaScriptオブジェクトではありません。
これが私のクラウド機能です。誰かが何かを見つけますか?
imageTagger.js
import * as functions from 'firebase-functions'
import * as admin from 'firebase-admin'
import * as vision from '@google-cloud/vision'
// Instantiate a vision client
const client = new vision.ImageAnnotatorClient()
const bucketName = 'demobucket'
export const imageTagger = functions.storage
.bucket(bucketName)
.object()
.onFinalize(async (object) => {
// return console.log('objectmetadata: ', object)
try {
const fileName = object.name
const imageUri = `gs://${bucketName}/${fileName}` // format required to send imageURLs to Google Vision
const [result] = await client.documentTextDetection(imageUri)
const fullTextAnnotation = result.fullTextAnnotation
const docRef = admin.firestore().collection('photosText').doc('test')
return docRef.set(JSON.stringify(fullTextAnnotation.text))
} catch (error) {
return console.error('error in this function', error)
}
})
電話をかけるJSON.stringify
と、文字列が返されます。また、文字列はFirestoreのフィールドの有効な値ですが、ドキュメント全体を不可能な文字列に設定しようとしています。
return docRef.set(JSON.stringify(fullTextAnnotation.text))
特定のフィールドを次の値に設定する必要があります。
return docRef.set({ text: JSON.stringify(fullTextAnnotation.text) })
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加