0

I am trying to load a csv file in the Cumulocity -> Administration - > Management - > File Repository. My objective is to access the file contents in the HTML widget and show the data in tabular or chart format. I tried using the fetch() method to use csv file url , but it was not able to fetch the file. The file I believe has been locally stored into the Cumulocity platform now. How can I access the file via fetch().

1 Answers1

2

You are trying to abuse the HTML widget for something it wasn't designed for.

Instead of hacking such logic into the HTML widget you should just extend the Cockpit application with your own widget which is honestly not much more difficult using the WebSDK. https://cumulocity.com/guides/web/introduction/

There is a XSRF protection to prevent exactly what you are currently trying: Bringing in custom javascript code into the live application and trying to access the platform API by "hijacking" the cookies of the logged in user (and you would either need the cookies or hardcode some credentials as you cannot access the API unauthenticated).

If you use the SDK there is even a proper Angular service in order to fetch the file for the API.

TyrManuZ
  • 2,039
  • 1
  • 14
  • 23
  • Thanks for your suggestions and concern as well. However I was not using any custom or external JS , just use the csv data to create a tabular format. I believe that much of simple javascript/html is allowed and it will not hamper any security of the platform. However I will definitely look into your suggestion and follow that route. – abir banerjee May 28 '20 at 08:38