Refresh image after upload

I’ve created a smart action that uploads an image to an S3 bucket. Everything is correct but I can’t get an image in a summary view to refresh after upload. It is based on the example provided in the docs.

What am I missing?

router.post('/actions/upload-logo', permissionMiddlewareCreator.smartAction(), (req, res) => {
  // Get the current company id
  const partnerId = req.body.data.attributes.ids[0];

  // Get the values of the input fields entered by the admin user.
  const attrs = req.body.data.attributes.values;
  const image = attrs['Logo Image'];

  P.all([
    uploadLogo(partnerId, image),
  ])
    .then(() => {
      // Once the upload is finished, send a success message to the admin user in the UI.
      return res.send({ success: 'Logo has been uploaded.' });
    });
});

Hi @jonl :wave: !

Where is that url ? On a relationship or on the current record ?

Current. I saw the examples to refresh relations but wasn’t able to find how to do it for current.

Can you check your network tab. Normally a request is sent to refresh your record just after the action has replied. Is it the case ?

It does indeed.

Things that come to my mind:

  • The name of the file is the same and therefore the URL path is the same.
  • It’s being server from a CDN.

Could it be that the browser is not downloading the new image as the url is the same and it’s being cached? I’ve had this issue in the website and I’ve workaround this by adding a dummy query parameter with a timestamp to the image URL.

Yes, I’m pretty sure that’s the issue. That is actually the issue on all website, when not updating an url it does keep the image in cache :disappointed: so the solutions are to either change the url or like you said add a dummy query parameter to the url (Just the one return no need to update it in DB)

1 Like

Thanks for confirming.

I returned in the smart field the URL with a dummy query parameter and the new file is downloaded by the browser and shown appropriately in the UI.

Here the code for the smart field in case anyone has a similar scenario.

fields: [{
    field: 'logo_smart',
    type: 'String',
    get: (record) => {
      if (record.logo)
      return 'https://website.url/'+record.logo+'?'+Date.now();
    },
  }
1 Like