ipfs-mini icon indicating copy to clipboard operation
ipfs-mini copied to clipboard

Question: Uploading files other than json or strings?

Open saskakol opened this issue 8 years ago • 8 comments

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 :)

saskakol avatar May 20 '17 09:05 saskakol

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

SilentCicero avatar May 21 '17 15:05 SilentCicero

@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?

saskakol avatar May 21 '17 15:05 saskakol

@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!

ngaer avatar Jun 19 '17 22:06 ngaer

@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 avatar Jun 22 '17 13:06 SilentCicero

@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.

SilentCicero avatar Jun 27 '17 00:06 SilentCicero

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

ngaer avatar Jun 27 '17 13:06 ngaer

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 ?

KarthikSamaganam4 avatar Sep 26 '18 10:09 KarthikSamaganam4

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])

alexstep avatar Mar 07 '21 20:03 alexstep