filestack / filestack-js

Official Javascript SDK for the Filestack API and content ingestion system.
https://www.filestack.com
MIT License
206 stars 76 forks source link

storeURL error: invalid security policy path #556

Closed ly-tc closed 3 months ago

ly-tc commented 3 months ago

Getting invalid security policy path error from storeURL

Expected Behavior

storeURL should work correctly

Current Behavior

storeURL returning security policy path error

Steps to Reproduce (for bugs)

const crypto = require('crypto');
const { Filestack } = require('filestack-js');

(async () => {
  const apiKey = 'your-api-key';
  const apiSecret = 'your-api-secret';

  const policy = Buffer.from(
    JSON.stringify({
      call: ['store'],
      expiry: Math.floor(Date.now() / 1000) + 60 * 60 * 24 * 2,
    })
  )
    .toString('base64')
    .replace(/[+\-/]/g, '_');

  const hmac = crypto.createHmac('sha256', apiSecret);
  hmac.write(policy);
  hmac.end();

  const signature = Buffer.from(hmac.read()).toString('hex');
  const client = Filestack(apiKey, {
    security: {
      policy,
      signature,
    },
  });
  const response = await client.storeURL('https://images.unsplash.com/photo-1710667069063-55d8afe19014');
  // response.data = { error: 'invalid security policy path' }
  console.log(response);
})();

Your Environment

ly-tc commented 3 months ago

The issue has been resolved by Filestack engineering team. Closing this!