Another Social Network for IPFS. . . Oh My!

So, about a year ago, I posted in this forum about a social network I wanted to make. I got a useful suggestion, and then backed out. IPFS had a single hang-up I couldn’t see my way around: there seemed to be no way to write files directly from memory, instead of writing them to the hard drive first, and then transferring them over to another part of the hard drive – which, to me, seems silly. I might as well be running gneutella – no offense.

So, I waited. . . and waited. . . and waited. The problem is, when I get something in my head, it doesn’t want to leave. It’s like a hair stuck in a biscuit. No matter how hard I tug, I can’t manage to free it from my mind. IPFS seems to be the best platform for my needs. I’ve considered a lot of alternatives, like TOR, but I don’t want a network of anonymous degenerates posting CP photos to others, and never getting caught.

And like all programmers with an obsession, I’ve returned to my desire for a social network over and over again.

At this point, I don’t know why. But my hang-up has yet to be fixed. I don’t know if I’m doing something wrong, or if IPFS doesn’t work the way I think it does. But I can’t get it to do this one simple thing (write directly to the IPFS, bypassing the FS). And the Python libraries I’ve used all seem to be incompatible with the current version, so I’m forced to build from scratch.

Everything works until I get to this one particular API call, then it all falls apart, I give up, and feel like quitting.

My current solution:
r = requests.post(“http://localhost:5001/api/v0/files/write?arg=/GANN/friends.txt&create=True”, data = {“data”:“This is a test!”})
print(r.text)
But IPFS complains:
file argument ‘data’ is required
And then I have no idea what I’m doing wrong.

I’m really stumped, and can’t think my way out of this. I’ve used Google, but it keeps referring me to incompatible libraries. At the moment, I’m thinking I may have to use BytesIO in some fancy way, but again, Google isn’t helping. Keeps referring me to the aforementioned libraries, instead of raw code.

I guess my hope lies with you guys now. All suggestions are very much appreciated at this point.

Thanks for your time.

2 Likes

Hi I got this code working using the requests module:

import requests

params = (
    ('arg', '/friends.txt'),
    ('create', 'True'),
)

files = {
    'file': ('myfile', open('test.txt', 'rb')),
}

response = requests.post('http://localhost:5001/api/v0/files/write', params=params, files=files)

where test.txt is a file on disk though it should work with any binary data from memory or elsewhere, hope it helps

1 Like