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

Lesson Feedback%3A Regular Files API - Lesson 4 (Read the contents of a file) #812

Open
heaversm opened this issue Jun 28, 2022 · 0 comments
Labels
lesson-feedback Feedback on a specific lesson

Comments

@heaversm
Copy link

heaversm commented Jun 28, 2022

Have a question or suggestion regarding a specific ProtoSchool lesson? Please use this template to share it!

URL of the lesson that's confusing:

https://proto.school/regular-files-api/04

What's confusing about this lesson?

In your example, calling toString() returns a readable string. In my own prototype - uploading a plaintext .txt file and then trying to read that back from the CID path results in an array of numbers using the same code:

const ipfsID = { path: 'QmUUSLeERmuFa63g6aFx7niouQyRUbHq81VXBgiCadPVZt' };
const bufferedContents = await toBuffer(ipfs.cat(ipfsID.path));
console.log(bufferedContents); //ouputs "Uint8Array(57)[[ 76, 105, 110, 107, 101, 100, 73, 110, 32, 45...]"
const stringContents = bufferedContents.toString();
console.log(stringContents); //outputs "76, 105, 110, 107, 101, 100, 73, 110, 32, 45..."

I realized this is because an uploaded plaintext file (say, via a file upload box) doesn't get stored as text, it gets stored as a file, so to read its contents you have to do something like

const fileURL = `https://ipfs.io/ipfs/${ipfsID.path}`;

fetch(fileURL)
.then( data => data.text() )
.then( fileContents => {
  setFileContents(fileContents);
  setImgURL(null);

What additional context could we provide to help you succeed?

how to read the contents of an uploaded .txt file to a string from an IPFS CID Path

What other feedback would you like to share about ProtoSchool?

Pretty good! Enjoying it.

@heaversm heaversm added the lesson-feedback Feedback on a specific lesson label Jun 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lesson-feedback Feedback on a specific lesson
Projects
None yet
Development

No branches or pull requests

1 participant