I'd like to override the upload behavior of a django ImageField so that after uploading to some url, the file will be added to an ipfs node.
For example, my model is something like:
class Profile(models.Model):
picture = models.ImageField(upload_to=upload_location, blank=True)
I first try saving it as you would any other image, but then I give it an IPFS hash, which will allow the user to load the data client side.
In my views I have the following code to get an instance of ipfs daemon running.
import ipfsapi
from subprocess import call
os.system("ipfs daemon")
api = ipfsapi.connect('127.0.0.1', 5001)
When I try to run python manage.py makemigrations
or runserver
, however, the daemon runs but the rest of the command doesn't.
Initializing daemon...
Swarm listening on /ip4/127.0.0.1/tcp/4001
Swarm listening on /ip4/174.56.29.92/tcp/4001
Swarm listening on /ip4/192.168.1.109/tcp/4001
Swarm listening on /ip6/::1/tcp/4001
API server listening on /ip4/127.0.0.1/tcp/5001
Gateway (readonly) server listening on /ip4/127.0.0.1/tcp/8080
Daemon is ready
How can I start an ipfs daemon and also a django server? It doesn't look like they're listening on the same port (Django 8000, IPFS 8080), so why am I running into this problem?