Thunkable X - Reading file from .txt

Hi everybody,
i’m struggling with an option i thought it would have been easier.
I really want to set a label text from reading a .txt file.

What I have done so far is:
When Screen opens:
from Label set Text to “//NameFile.txt

Am I doing something wrong? It doesn’t read what it’s inside the file but will show just the name of it.

I uploaded already the file on my design page and the name is correct 100%.

Thank you.

Are you just wanting to view the contents of the text file or do you need to use the data within it for other purposes?

Typically, to use the data, you’d need to paste it in to a variable or local/external data source as a csv or JSON value.

You could try to use the webviewer and an html file for this kind of task. There is no way to assign a text value from a text file at this time based on a recent conversation about access root files.

I’ve done this before and it’s pretty simple!
All you have to do is have somewhere public where to host information like github. Upload your txt file and use the web API component.

What you have is a long sting of your data. So I would put certain things in your text to get like an ID and the value.

That way you if you get that string and divide it into a list using the block
image

You get your data, then you can store it in your app as variables.

To change the labels let’s say to a specific language all you have to do is just change the URL you’re using for the labels :slight_smile:

2 Likes

I just want to view te contents

Sorry it really goes beyond my capabilities.
I’ll try but it looks very hard to me

The scrFileViewer screen in this project looks promising for that: Reading text files from device

1 Like

It’s okay! :slight_smile: Start solving it bit by bit. I encourage you to look at the official documentation:

Web API --> https://docs.thunkable.com/web-api

How to create a document in Github --> https://docs.github.com/en/free-pro-team@latest/github/managing-files-in-a-repository/creating-new-files

BTW Be sure to use the RAW link you get when you upload a file in Github for the url. Really important!

Thank you for your help, it looks indeed promising but it says it just works on iOs and not with Android. I really need something it can be used in both of them

Sofia

I have been trying to figure out how to upload text into Thunkable. Do you have any links/examples of the GitHub Web API to either download or upload a file? That would be HUGE for my project.

Thanks!

Sure, it’s not actually like uploading is like retrieving from the web. If you want to upload contents as a txt file then you would need a custom API to save that data and save it to a database like airtable or sheets (taking in consideration the character limits)

To just retrieve data:
You make a txt file in Github :slight_smile: To just use github to retreive data. I use it to have multiple languages and add more as I develop the app.
The raw link you get from github that’s your ‘new’ txt file.

Then you use web api and parse the response however you want it :slight_smile:

@drted I just tried it out myself and got it to work. I thought I was going to access the text file as a JSON object but I ended up just pulling the text and parsing it by newlines as a list.

I pasted the text file contents into GitHub but there’s probably a way to upload a text file directly. Here’s a link to that text in GitHub:

And the sample project that pulls the 5th line from the text file (“was”):

Edit: And I was able to find the upload button and upload a different text file. If you open the sample project from the project link above and change the url to https://raw.githubusercontent.com/tatiang/datasources/main/typing.txt, you’ll get the 5th word/line of that text file, “jumps”.

1 Like

Thanks Sofia and tatiang!!! I’ll play around with these techniques. I am wondering if I could combine this technique ( https://github.community/t/how-to-upload-a-file-using-github-api/14031/2) to use the web api to both upload to github then download into Thunkable.

If all else fails, I may resort to writing a bit of PHP/Javascript on my domain server to upload the file. I’ll keep you posted.

Thanks again!!!

I probably will need my app to work offline as well.
I’ll try to write an csv file and upload it in order to get the lines I need from there.

The app is a Cocktail List recepies where at one click on the cocktail on a list.Viewer, it opens a screen loading the info of that cocktail

Hi everybody, it seems like I have found a decent option.
I’m using Local Database instead, even tough it’s not the same.
Thank you everybody to reply