1

I'm working on a project where I wish to upload some images to IPFS, but the issue is I have the URL for the images, is there any way to upload the image using the URL? Like I was searching for ways to do this but all I could find is I can use images in jpeg, png etc formats for the IPFS API. Please help me out with this query

4 Answers 4

1

if you want to stay purely decentralized, do not do this under any circumstances UNLESS your url is another IPFS reference:

{
"image":url
}

I've seen some NFTs rugpulling due to the centralized factor. If your IPFS is going to point to an image on the standard web, why even bother to use IPFS?

You haven't explained which technology stack you are using so can't give you an exact answer, however your solution will look like this:

  1. Make a GET request to the URL you wish to get the image from (if you're using nodejs, you can easily do this via axios)
  2. Store it as base64 format in your state
  3. Upload it on IPFS

Again, assuming you're using Nodejs, it's pretty easy to upload over IPFS a base64 string image

import { fromString } from 'uint8arrays/from-string'

const data = fromString(base64_string, 'base64')
const { cid } = await ipfs.add(data)

console.info(cid)

Reference for code above here.

1
  • hey, thanks a lot, i will try this
    – Prajwal K
    Jan 28, 2023 at 12:30
0

Why not simply download the image from the link and upload it to IPFS?

Otherwise, you could do similar to what people do with NFTs, which is to create a JSON with an image tag in which you insert the link and store that on IPFS. You can store any type of file on IPFS.

2
  • So instead of using the IPFS url of the image you're suggesting me to just add the normal url to the object and upload that object to IPFS? will that be okay?
    – Prajwal K
    Jan 16, 2023 at 14:04
  • It will work, but it depends on what you want to achieve. It will store the file with the URL to your image on IPFS.For example, if you want Opensea to be able to see your image it will work. You can read more about Opensea metadata here: docs.opensea.io/docs/metadata-standards
    – Nal Luksic
    Jan 16, 2023 at 14:15
0

In case of NFT, if you already have images uploaded somewhere then this is a good news because the NFT contract looks up at metadata. Just prepare metadata json files and upload those files to the ipfs. You can just use image url in metadata image field. Eg. in metadata:

{
  .....
  image:"image url"
  .....
}
0

You dont have to reupload your images, you can upload the metadata and use the image URL inside the image: field.

Here is an example on how to upload metadata to IPFS using Moralis IPFS API. https://docs.moralis.io/web3-data-api/evm/how-to-upload-nft-metadata-to-ipfs

Let me know if you need any help!

Disclosure: I work at Moralis

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.