title: How do I load an image from a url, and then add it to IPFS?
body: <p>I want to load an image from some url like <code>https://example.com/picture1.png</code>.</p>
  <p>Then, I want to figure out:</p>
  <ul>
  <li>The image's width (which I can)</li>
  <li>The image's height (which I can)</li>
  <li>The image's keccak256 hash (which I can)</li>
  <li><strong>The image's IPFS CID</strong> (which I can't)</li>
  </ul>
  <p>I'm trying to do it with <code>ipfs-mini</code>.</p>
  <p>My code:</p>
  <pre><code>const axios = require(&quot;axios&quot;);
  const Web3 = require(&quot;web3&quot;);
  const IPFS = require('ipfs-mini');
  const sizeOf = require('image-size');
  
  const web3 = new Web3();
  const ipfs = new IPFS({ host: 'ipfs.infura.io', port: 5001, protocol: 'https' });
  
  const loadAndHashImage = async (_url) =&gt; {
      const response = await axios.get(_url,  { responseType: 'arraybuffer' });
      const buffer = Buffer.from(response.data, &quot;utf-8&quot;);
  
      const dimensions = sizeOf(buffer);
      console.log(&quot;Image Width:&quot;, dimensions.width)
      console.log(&quot;Image Height:&quot;, dimensions.height)
  
      const imageIpfsCid = await ipfs.add(buffer);
      console.log(&quot;Image IPFS CID:&quot;, imageIpfsCid); // is different for some reason
  
      const imageHash = web3.utils.keccak256(buffer);
      console.log(&quot;Image Hash:&quot;, imageHash);
  
      const urlIpfsCid = _url.substring(21)
      console.log(&quot;NEEDS TO BE TRUE:&quot;, imageIpfsCid === urlIpfsCid)
  }
  
  loadAndHashImage(&quot;https://ipfs.io/ipfs/QmSsYRx3LpDAb1GZQm7zZ1AuHZjfbPkD6J7s9r41xu1mf8&quot;);
  </code></pre>
  <p><em>(Right now, I'm passing in a IPFS url because it allows me to know beforehand what IPFS CID I should be getting in the <code>imageIpfsCid</code> variable.)</em></p>
  <p>Currently, <code>imageIpfsCid</code> is different from the original passed in CID, which means something is wrong.</p>
  <p>If I go to <code>imageIpfsCid</code>, instead of viewing an image, my computer automatically starts downloading a file, which makes me suspect that I'm not actually adding the image to IPFS, but it's data.</p>
  <p>However, I can't seem to figure out how to fix this.</p>
  <p>Once it's fixed, the passed in CID and <code>imageIpfsCid</code> should be a match.</p>