如何遍历 cloudinary 查询的结果
How to iterate through the result of a cloudinary query
我将一个视频上传到 cloudinary,该视频由“google 视频审核”进行审核。如果视频审核状态已获批准,我想保存视频的 public_Id 和 url。我已经能够成功地为视频查询 cloudinary,但我不知道如何遍历查询结果。我需要使用 NodeJS 进行迭代并从结果中仅获取 public_Id 和 url。
我还没有尝试过任何东西,因为我是 NodeJS 的新手。
查询结果:
{
resources: [
{
asset_id: '54598f6f952b934d45b9b8dfa3b9298f',
public_id: 'm7zp9okftllenzmigyng',
format: 'mp4',
version: 1629500308,
resource_type: 'video',
type: 'upload',
created_at: '2021-08-20T22:58:28Z',
bytes: 1004360,
width: 640,
height: 352,
url: 'http://res.cloudinary.com/dt3ic2vk7/video/upload/v1629500308/m7zp9okftllenzmigyng.mp4',
secure_url: 'https://res.cloudinary.com/dt3ic2vk7/video/upload/v1629500308/m7zp9okftllenzmigyng.mp4'
}
],
rate_limit_allowed: 500,
rate_limit_reset_at: 2021-08-21T00:00:00.000Z,
rate_limit_remaining: 490
}
我们可以使用 Array.prototype.forEach()
function to iterate through all the objects (videos) in the resources
object and use Array.prototype.push()
function 将值添加到数组中(作为示例)。
// initialize a new array called "results"
let results = [];
// for each object (initialized as "videoObject") in the "resources" object
result.resources.forEach(videoObject => {
// add the "public_id" and "url" keys into the "results" array.
results.push(videoObject.public_id, videoObject.url)
});
我将一个视频上传到 cloudinary,该视频由“google 视频审核”进行审核。如果视频审核状态已获批准,我想保存视频的 public_Id 和 url。我已经能够成功地为视频查询 cloudinary,但我不知道如何遍历查询结果。我需要使用 NodeJS 进行迭代并从结果中仅获取 public_Id 和 url。 我还没有尝试过任何东西,因为我是 NodeJS 的新手。
查询结果:
{
resources: [
{
asset_id: '54598f6f952b934d45b9b8dfa3b9298f',
public_id: 'm7zp9okftllenzmigyng',
format: 'mp4',
version: 1629500308,
resource_type: 'video',
type: 'upload',
created_at: '2021-08-20T22:58:28Z',
bytes: 1004360,
width: 640,
height: 352,
url: 'http://res.cloudinary.com/dt3ic2vk7/video/upload/v1629500308/m7zp9okftllenzmigyng.mp4',
secure_url: 'https://res.cloudinary.com/dt3ic2vk7/video/upload/v1629500308/m7zp9okftllenzmigyng.mp4'
}
],
rate_limit_allowed: 500,
rate_limit_reset_at: 2021-08-21T00:00:00.000Z,
rate_limit_remaining: 490
}
我们可以使用 Array.prototype.forEach()
function to iterate through all the objects (videos) in the resources
object and use Array.prototype.push()
function 将值添加到数组中(作为示例)。
// initialize a new array called "results"
let results = [];
// for each object (initialized as "videoObject") in the "resources" object
result.resources.forEach(videoObject => {
// add the "public_id" and "url" keys into the "results" array.
results.push(videoObject.public_id, videoObject.url)
});