I use ipfs-http-client
to upload and retrieve my file. The following creates the client and uploads an image in base64 string:
import { create } from "ipfs-http-client";
let client = create("/ip4/127.0.0.1/tcp/5001");
let file = await client.add(somebase64imagestring);
Below is how I retrieve the file given the CID
let iter = client.cat(imageCID);
for await (let img of iterable) {
const imgStr = Buffer.from(img).toString();
}
The problem is intermittent. Sometimes, I get the full base64 string in imgStr
which is 19.9kb. Sometimes, I only get a portion of it like 11.8kb where the first few characters are missing. Even if I await
on the client.cat
which the VSCode highlights as no effect, and even if I do client.cat(imageCID, {offset: 0})
, still the returned image string is sometimes complete, and sometimes missing the first few parts.