使用IBM Cloud功能写入存储在IBM Cloud对象存储中的CSV文件

时间:2019-09-05 16:13:44

标签: node.js ibm-cloud-functions ibm-cloud-storage

我必须通过使用Node.js进行的IBM云功能读取存储在IBM云对象中的CSV文件。现在,我必须对该文件应用任何逻辑,然后通过IBM云功能将其写回。

我该怎么做(请输入代码)?

下划线是使用IBM Cloud函数中的“读取文件”操作从IBM云对象存储中读取CSV文件的代码。

const COS = require('ibm-cos-sdk')。S3;

异步函数main(params){

const IAM_API_KEY = process.env ['__ OW_IAM_NAMESPACE_API_KEY']

const ENDPOINT ='s3.eu-gb.cloud-object-storage.appdomain.cloud'

const BUCKET ='my-bucket'

const FILE ='Sample.csv'

const config = {

 endpoint: ENDPOINT,

 apiKeyId: IAM_API_KEY

}

const cos = new COS(config);

const options = {桶:BUCKET    }

异步函数getItem(bucketName,itemName){

console.log(Retrieving item from bucket: ${bucketName}, key: ${itemName});

try{
    const data = await cos.getObject({
    Bucket: bucketName, 
    Key: itemName
}).promise()

    if (data != null) {

        console.log('File Contents: ' + Buffer.from(data.Body).toString())
        console.log("hellllllo");

    }    
     return data
}
catch(e){
    console.error(`ERROR: ${e.code} - ${e.message}\n`)
}

}

console.log(等待getItem(BUCKET,FILE))

}

0 个答案:

没有答案