I have a simple webapp with a form to upload an image to IPFS. I am using ipfs-js-api to add the file to IPFS. Everything works well on my dev box. In production, I am using nginx. Since I can’t directly communicate with my IPFS daemon (localhost), I have a proxy set up so the frontend can communicate with the daemon through mydomain.com/ipfs/:443. However, when I upload a file, I get the error:
POST https://www.mydomain.com/ipfs/:443/api/v0/add?stream-channels=true net::ERR_CONTENT_LENGTH_MISMATCH
TypeError: network error
Uncaught (in promise) TypeError: network error
My code looks like this:
function saveImageOnIpfs(reader) {
return new Promise(function(resolve, reject) {
const buffer = Buffer.from(reader.result);
ipfs.add(buffer)
.then((response) => {
console.log(response)
resolve(response[0].hash);
}).catch((err) => {
console.error(err)
reject(err);
})
})
}
My nginx configuration is:
location /ipfs/ {
proxy_pass http://localhost:5001/;
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
Can someone help me with this issue?