0

I'm getting "401 Unauthorized" when I try to render or download images in a browser in product cards which is templated by EJS. I guess I should send an access token with GET request when I try to access the image to pass authorization but I don't know how to do it. Thanks in advance!

<body>
<% productsCollection.forEach(item => { name = item.name, price = item.salePrices[0].value / 100 + " AZN", itemID = item.id, image = item.customImageLink %>
<div class="card" style="width: 18rem;">
        <img src="<%= image %>" class="card-img-top" alt="...">
        <div class="card-body">
          <h5 class="card-title"><%= name %></h5>
          <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
          <a href="#" class="btn btn-primary"><%= price %></a>
        </div>
      </div>
 <% }) %>
</body>
Jeyhun085
  • 21
  • 4
  • Are you not storing your images in folder which is added as public folder in app.js ? – Vipulw Jan 03 '22 at 07:27
  • I'm not storing images in local folders at all. I take the image URL from the object of each product. That means images are stored on a remote server which declines access when I try to render them. – Jeyhun085 Jan 03 '22 at 07:36
  • That strongly depends on the authorization scheme on your server. You cannot add authorization headers for statically linked resources like ` – derpirscher Jan 03 '22 at 07:36
  • I know it can seem like a too-simple question, but how can I add an authorization header to URL or IMG tag. I know how to do it with Axios or other request tools, but this is the first time I have encountered this type of problem – Jeyhun085 Jan 03 '22 at 07:47
  • @Jeyhun085 It's *not possible* to add an authorization header to an `` tag. – derpirscher Jan 03 '22 at 08:15
  • @derpirscher Okay, then how can the browser pass authorization when it tries to render an image by URL? – Jeyhun085 Jan 03 '22 at 08:40
  • @Jeyhun085 Need to understand more of your asset storage server. Where are you storing those images ? – Vipulw Jan 03 '22 at 09:44
  • @Vipulw You can check directly the URL [link](https://online.moysklad.ru/api/remap/1.2/download/5ca9b458-31f0-45ee-a471-50642e9c2ca4) – Jeyhun085 Jan 03 '22 at 11:01
  • This links seems to be pointing to a secured CRM system and yes you need to send a authorization to it. And only possible if you know more information of that CRM – Vipulw Jan 04 '22 at 07:57
  • Refer this link from documentation https://dev.moysklad.ru/doc/api/remap/1.2/#mojsklad-json-api – Vipulw Jan 04 '22 at 07:59

0 Answers0