如何解决谷歌云存储获取点击图片元数据信息
我有一个 Node.js 后端 React 前端应用程序。在我的 React 应用程序中,我列出了几张从 Google Cloud Storage 中获取的图像,当单击图像时,将打开一个弹出页面,在弹出页面中,我想以更大的比例显示单击的图像、元数据信息和位置信息(取自ip)。
我可以获取任何图像(一张图像)的元数据信息。获取一张图片元数据信息的代码:
const express = require("express");
const cors = require("cors");
// Imports the Google Cloud client library
const { Storage } = require("@google-cloud/storage");
const bucketName = "myBucket";
const filename = "detected/0.jpg";
const storage = new Storage();
const app = express();
app.get("/api/Metadata",cors(),async (req,res,next) => {
try {
// Gets the Metadata for the file
const [Metadata] = await storage
.bucket(bucketName)
.file(filename)
.getMetadata();
const Metadatas = [
{id: 0,name: `Date: ${Metadata.updated.substring(0,10)},Time: ${Metadata.updated.substring(11,19)}`},{id: 1,name: Metadata.contentType}
];
res.json(Metadatas);
} catch (e) {
next(e);
}
});
const port = 5000;
app.listen(port,() => console.log(`Server started on port ${port}`));
但是,我不知道如何获取点击图像的元数据信息。如何获取被点击元素的元数据?
解决方法
当您在 React Frontend 上显示这些图像时,每个图像都会关联一个 Class V1
1 Ciliates 136640.1
2 Dinoflagellates NA
3 Dinophyceae 0.0
Warning messages:
1: In averages * diff(x$Depth) :
longer object length is not a multiple of shorter object length
。
现在,任何图像的 filename
都会将此 onClick
发送到后端 API 以获取元数据。
并且在您的 fileName
您应该从 app.get("/api/metadata",cors(),async (req,res,next) => {
请求对象中提取您的 fileName
,作为参数或查询字符串,并使用该 req
而不是 fileName
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。