SilentCicero / ipfs-mini

A super tiny module for querying IPFS that works in the browser and node.
MIT License
152 stars 40 forks source link

Question: Uploading files other than json or strings? #4

Open saskakol opened 7 years ago

saskakol commented 7 years ago

Hi! I have a quick question: Is it possible to upload other types of files over ipfs-mini than just text? I would need to upload .gif files, and I don't know if I can use IPFS.js, so came to ask here.

Thanks, Sas :)

SilentCicero commented 7 years ago

So you might be able to by using the blob mechanism in the browser. Are you using this in nodejs or the browser?

saskakol commented 7 years ago

@silentcicero I'm using the browser. I actually figured out that I can just store a base64 string, which should work fine for what I'm doing. Thanks for the help though :)

Btw, what is a good IPFS node to use? Infura doesn't allow it to be used in projects without explicit permission, and I would need it for a hackathon. (I don't know how fast they will respond) Are there any alternatives?

ngaer commented 7 years ago

@SilentCicero i'm trying to upload png/jpg files using blob mechanism, uploading works well, but when i watch these images using gateway, it seems like they are corrupted. If i upload files in the same way using js-ipfs-api, images are not corrupted. Do you know what could be the problem? Here's the code and example of corrupted image:

function uploadImage(file) {
    return new Promise((resolve, reject) => {
        const fileReader = new FileReader();

        fileReader.onload = event => resolve(event.target.result);
        fileReader.onerror = error => reject(error);
        fileReader.readAsArrayBuffer(file);
    })
    .then(arrayBuffer => (new Promise((resolve, reject) => {
        ipfs.add(Buffer.from(arrayBuffer), (error, hash) => error ? reject(error) : resolve(hash))
    })))
}

http://ipfs.io/ipfs/QmPTP3sjiXGy9jQcEZhexRYMSx5ZhSGdofHDkzG5DpvaQb

Thanks!

SilentCicero commented 7 years ago

@iSasFTW I would recommend just starting a local node up or using the main IPFS gateway if that is still running (they have a high performance cluster running, I believe for free).

@ngaer I'll try to complete this task myself. Not sure why it would be currupted. Let me ask Pelle:

@pelle any thoughts on the above?

I think it's because we wrote our own Blob wrapper, and it may be wrapping the data twice.

SilentCicero commented 7 years ago

@ngaer have you figured anything out, @pelle and I are too busy to investigate, but I will be using this module eventually to do file upload.

ngaer commented 7 years ago

No, i do not have much time for this too, so for now i decided to use js-ipfs-api on server side.

KarthikSamaganam4 commented 5 years ago

HI i have added one json object in IPFS using addJson method. But while i am trying to get the same json object back using catJson with proper hash code i am getting the json ..but the output json is not a valid json object. How can i get the parsed json object ?

alexstep commented 3 years ago

I use little hack for upload images - convert to svg

const reader = new FileReader()
reader.onloadend = async function () {
    const fileContents = `<svg xmlns="http://www.w3.org/2000/svg">
        <image href="${reader.result}" />
     </svg>`

  const CID = await IPFS.add(fileContents)
}
reader.readAsDataURL(this.files[0])