0

我正在使用 Wasabi DB,如果我理解正确的话,它的工作方式与亚马逊上的 S3 基本相同。但是,我对此没有太多经验。

现在,我正在使用云功能将一些“安全搜索”元数据添加到标题中。因此,每当上传新图像时都会调用它,最后一行代码验证元数据是否已成功添加。


export const classifyImage = functions.runWith(runtimeOpts).https.onRequest(async (req, res) => {
  let path = req.body?.path || req.query.path;
  if (!path) {
    res.send('No path provided');
    return;
  }

  const client = new ImageAnnotatorClient();
  const bucket = 'files.dabblewriter.com';
  if (path[0] === '/') path = path.slice(1);

  const [result] = await client.safeSearchDetection(
    `https://${bucket}/${path}`
  );
  const detections = result.safeSearchAnnotation;

  if (!detections) return;

  const head = await s3.headObject({ Bucket: bucket,  Key: path}).promise();
  console.log('metadata before is: ' + JSON.stringify(head.Metadata));

  const params: S3.CopyObjectRequest = {
    Bucket: bucket,
    CopySource: `${bucket}/${path}`,
    Key: path,
    Metadata:  {
      ...head.Metadata,
      'search-adult': '' + detections.adult,
      'search-spoof': '' + detections.spoof,
      'search-medical': '' + detections.medical,
      'search-violence': '' + detections.violence,
      'search-racy': '' + detections.racy,
    },
    'MetadataDirective': 'REPLACE',
  }

  await s3.copyObject(params).promise()

  console.log('successfully added metadata to photo', params);

  //I included this to verify that the new metadata was successfully added in the logs
  const data = await s3.headObject({ Bucket: bucket,  Key: path}).promise();

  console.log('metadata after is: ' + JSON.stringify(data.Metadata));

  res.send('classified photo')
});

我的问题出现在客户端,当尝试通过发出获取请求来访问这个新的元数据时。基本上看起来元数据没有被返回,(或者我看不到/找不到它)

我的传出获取请求对象的主体是

在此处输入图像描述

我得到的回应是

在此处输入图像描述

还值得一提的是,我正在使用服务人员来发出请求,所以这可能会导致 CORS 问题。

任何帮助表示赞赏。

4

0 回答 0