I was reading dozens of of articles, FAQs and other questions here on discuss the whole day. Yet, I canât find an answer about how to realize my use case:
IPFS Gateway: http://ipfs.example.com
Website: http://example.com (static Vue.js application to interact with IPFS and Ethereum)
No further server-side processing.
Within the JS application users are uploading images which in turn are written to the IPFS gateway:
import ipfsAPI from 'ipfs-api'
const ipfs = ipfsAPI('ipfs.example.com', '5001')
// ...
// Push to ipfs
let fileReader = new FileReader()
fileReader.onload = e => {
const buffer = Buffer.from(fileReader.result)
ipfs.add(buffer, {progress: this.progress})
.then((response) => {
console.log('ipfs hash', response[0].hash)
// ...store hash in ethereum...
})
}
Problem 1:
ipfs.add()
does not allow to add the file to a specific directory. Iâd have to use object.patch.addLink
to append the uploaded file to a known directory object and have to store the new hash somewhere for subsequent users.
Problem 2:
The directory objects hash changes everytime someone adds a file, which can happen multiple times per second. Itâs impossible to guarantee that all current clients are in sync about what the current hash is.
Problem 3:
Even though I can restrict access to the gateway via CORS to just example.com, a malicious user could still manipulate the clientside javascript to circumvent the restriction of uploading jpeg and png files.
Question 1: Is there any other method to tell the gateway âAdd this file to latest version of folder XYZ - you know its hash - and only if the file mime type is either image/png or image/jpegâ?
Problem 4:
All images are loaded individually in image tags like this:
<img src="http://ipfs.example.com/ipfs/QmRuzPpc1tjJ5TbhG7B2Ato8LtaY2DK2Y5DMWWb29cqFF5"/>
A malicious user could just press F12 and enter any hash he wants, forcing my gateway to load illegal content.
Question 2: Is it possible to configure a gateway to serve only already pinned files?
Has anyone yet build a serverless single page application which stores user data in IPFS? How did you circumvent these problems?
Is that only possible by hiding the gateway behind some serverside logic (e.g. a node server which queues the uploads + adds the files to IPFS + keeps track of the latest directory hash + also stores the images outside of IPFS to serve as <img>
source to prevent loading of unpinned content)?