PinataCloud / Pinata-SDK

Official SDK for the Pinata IPFS service
MIT License
273 stars 67 forks source link

API psa/add Not Found when using ipfs-http-client #87

Closed santiq closed 1 year ago

santiq commented 2 years ago

When trying to use the psa/add endpoint

Error uploading file 0 HTTPError: Not Found
    at Object.errorHandler [as handleError] (/Users/xxx/xxx/metaplex/js/node_modules/ipfs-http-client/src/lib/core.js:100:15)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async Client.fetch (/Users/xxx/xxx/metaplex/js/node_modules/ipfs-utils/src/http.js:145:9)
    at async addAll (/Users/xxx/xxx/metaplex/js/node_modules/ipfs-http-client/src/add-all.js:40:17)
    at async last (/Users/xxx/xxx/metaplex/js/node_modules/it-last/index.js:13:20)
    at async Object.add (/Users/xxx/xxx/metaplex/js/node_modules/ipfs-http-client/src/add.js:23:14) {
  response: Response {
    size: 0,
    timeout: 0,
    [Symbol(Body internals)]: { body: [PassThrough], disturbed: true, error: null },
    [Symbol(Response internals)]: {
      url: 'https://api.pinata.cloud/psa/add?stream-channels=true&progress=false',
      status: 404,
      statusText: 'Not Found',
      headers: [Headers],
      counter: 0
    }
  }
}

My code:

 const ipfs = create({
    url: 'https://api.pinata.cloud/psa',
    headers: {
      "Authorization": `Bearer ${ipfsCredentials.accessToken}`
    }
   });

  const uploadToIpfs = async source => {
    const { cid } = await ipfs.add(source).catch();
    return cid;
  };

  const mediaHash = await uploadToIpfs(globSource(image, { recursive: true }));

  log.debug('mediaHash:', mediaHash);

  const mediaUrl = `https://ipfs.io/ipfs/${mediaHash}`;

  log.debug('mediaUrl:', mediaUrl);

  await fetch("https://api.pinata.cloud/pinning/pinByHash", {
    headers: {
      "Authorization": `Bearer ${ipfsCredentials.accessToken}`
    },
    method: 'POST',
    body: JSON.stringify({
      hashToPin: mediaHash
    })
  });
  log.info('uploaded image for file:', image);

maybe related to #52

rommel-pinata commented 1 year ago

hello @santiq as mentioned by Matt this is not possible https://github.com/PinataCloud/Pinata-SDK/issues/52#issuecomment-867036544