質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Google Cloud Platform

Google Cloud Platformは、Google社がクラウド上で提供しているサービス郡の総称です。エンドユーザー向けサービスと同様のインフラストラクチャーで運営されており、Webサイト開発から複雑なアプリ開発まで対応可能です。

Google API

Googleは多種多様なAPIを提供していて、その多くはウェブ開発者向けのAPIです。それらのAPIは消費者に人気なGoogleのサービス(Google Maps, Google Earth, AdSense, Adwords, Google Apps,YouTube等)に基づいています。

Node.js

Node.jsとはGoogleのV8 JavaScriptエンジンを使用しているサーバーサイドのイベント駆動型プログラムです。

Q&A

解決済

1回答

17668閲覧

ENOENT: no such file or directoryを解決したい。

kozukata

総合スコア9

Google Cloud Platform

Google Cloud Platformは、Google社がクラウド上で提供しているサービス郡の総称です。エンドユーザー向けサービスと同様のインフラストラクチャーで運営されており、Webサイト開発から複雑なアプリ開発まで対応可能です。

Google API

Googleは多種多様なAPIを提供していて、その多くはウェブ開発者向けのAPIです。それらのAPIは消費者に人気なGoogleのサービス(Google Maps, Google Earth, AdSense, Adwords, Google Apps,YouTube等)に基づいています。

Node.js

Node.jsとはGoogleのV8 JavaScriptエンジンを使用しているサーバーサイドのイベント駆動型プログラムです。

0グッド

0クリップ

投稿2020/06/30 09:19

実現したいこと

Google Cloud Vision API: Node.js Client #Quickstart
こちらのREADMEに従ってQuickstartを成功させたい。

前提

現在の作業ディレクトリは以下の通りです。

├── node_modules ├── src │ ├── vision.js │ └── cat.jpg ├── package.json └── yarn.lock

ソースコード

vision.js

js

1async function quickstart() { 2 // Imports the Google Cloud client library 3 const vision = require('@google-cloud/vision'); 4 5 // Creates a client 6 const projectId = 'react-accountbook'; 7 const keyFilename = '../vision.service-account.json'; 8 const client = new vision.ImageAnnotatorClient({ projectId, keyFilename }); 9 10 // Performs label detection on the image file 11 const [result] = await client.labelDetection('./cat.jpg'); 12 console.log(result); 13 const labels = result.labelAnnotations; 14 console.log('Labels:'); 15 labels.forEach((label) => console.log(label.description)); 16} 17 18quickstart();

発生している問題

vision.jsを実行すると、以下のように./cat.jpgは存在しないというエラーが発生します。
vision.jscat.jpgは確かに同じディレクトリにあります。

$ node ./src/vision.js ✘ 1 (node:25188) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, open './cat.jpg' (node:25188) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:25188) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

試したこと

const [result] = await client.labelDetection('./cat.jpg');を絶対パスで表記してみましたが結果は変わりませんでした。

補足情報

nodeのバージョンは10.17.0です。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

実行が

$ node ./src/vision.js

なのであれば、

const [result] = await client.labelDetection('./src/cat.jpg');

だと思います。

パスの指定は、

__dirname + "/cat.jpg"

でも良いと思います。
(絶対パスだとダメ、というのはおかしい気がしますが...)

投稿2020/06/30 09:55

tetsunosuke

総合スコア1292

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

kozukata

2020/06/30 10:13

おかげさまで解決いたしました。 実行するディレクトリからのパスで書かなければ行けなかったんですね。初歩的なミスで失礼いたしました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問