Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

还维护? #19

Open
lishaoxin123 opened this issue Oct 14, 2022 · 1 comment
Open

还维护? #19

lishaoxin123 opened this issue Oct 14, 2022 · 1 comment

Comments

@lishaoxin123
Copy link

https://support.huaweicloud.com/sdk-nodejs-devg-obs/obs_29_0404.html
只有文件的buffer流,怎么使用ObsClient 进行文件上传呢?总不能走一遍写入然后读取成功在删除吧。

@noaccident
Copy link
Collaborator

需要buffer转stream,然后再调用sdk的上传接口。可参考以下代码:

let Duplex = require('stream').Duplex;

function bufferToStream(buffer) {  
  let stream = new Duplex();
  stream.push(buffer);
  stream.push(null);
  return stream;
}

const buffers = []; // 文件buffer

const stream = bufferToStream(buffers);

obsClient.putObject({
    Bucket : bucketName,
    Key: 'objectname',
    Body: stream
}).then(res => console.log(res));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants