How to get a file format icon for any file type in Node.JS
File type icons are important for a properly intuitive user experience. Automating the process of retrieving the appropriate icon for a given file format can be a bit irksome, and so I have created a simple to use API that will take care of this for you. Setting up this API will take but a few minutes of your valuable time.
Add a reference to your package.json file for our API client, as seen below.
"dependencies": {
"cloudmersive-convert-api-client": "^2.1.6"
}
Now it’s time to call convertDocumentGetFileTypeIcon, which just needs the file’s extension as an input parameter, as well as optionally the desired icon size.
var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');var defaultClient = CloudmersiveConvertApiClient.ApiClient.instance;// Configure API key authorization: Apikeyvar Apikey = defaultClient.authentications['Apikey'];Apikey.apiKey = 'YOUR API KEY';// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.apiKeyPrefix = 'Token';var apiInstance = new CloudmersiveConvertApiClient.ConvertDocumentApi();var fileExtension = "fileExtension_example"; // String | Required; The file extension to be used for the icon. Limited to 4 AlphaNumeric characters.var opts = {'iconSize': 56 // Number | Optional; The desired width of the icon, preserving its aspect ratio.};var callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.convertDocumentGetFileTypeIcon(fileExtension, opts, callback);
Now run it and you will have your icon soon after.