Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
84 views
in Technique[技术] by (71.8m points)

javascript - How can I use a buffer as image (without writing it as a file and read again)

  buffer = canvas.toBuffer("image/jpeg");
  await fs.writeFileSync(id + ".jpeg", buffer);
  (async() => {
    var { media } = await client.uploadPhoto({
      photo: id + ".jpeg",
      caption: "",
      post: "feed"
    });
    console.log(`https://www.instagram.com/p/${media.code}/`);
  })();

First I create a buffer to write a file. Then I write it to the current path with the name of id. In the async function, I try to get a photo as id+"jpeg". However, I don't want to do that because I run it on a server. Servers do not have storages. So it gives an error. I need something like

...client.uploadPhoto({
          photo: buffer.toImage(),
          caption: "",
          post: "feed"
        });

Any help is appreciated. Thanks in advance... The API that I use is this

question from:https://stackoverflow.com/questions/65642929/how-can-i-use-a-buffer-as-image-without-writing-it-as-a-file-and-read-again

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...