how to make a downloaded file has file name + file extension in its name?

how to make a downloaded file has file name + file extension in its name?

I want to download the file from 'File Upload' Field in Zoho CRM, after download the file then I will upload it to our own image server to create a download URL link. I wrote the code below.

but the problem is, the file name doesnt have file extension in it. so how to include a file name + file extension in the downloaded file name?

here is the code I use:

  1. // fetch CRM Deal Details
  2. v_Module = "Deals";
  3. v_dealID = DEAL_ID;
  4. v_Endpoint = "https://www.zohoapis.com/crm/v7/" + v_Module + "/" + v_dealID;
  5. r_DealDetails = invokeurl
  6. [
  7. url :v_Endpoint
  8. type :GET
  9. connection:"zoho_crm_connections"
  10. ];
  11. m_DealDetails = ifnull(r_DealDetails.get("data").toMap(),Map());
  12. if(!isNull(m_DealDetails.get("Product_Attachment")))
  13. {
  14. l_Files = List();
  15. for each  m_FileUpload in m_DealDetails.get("Product_Attachment")
  16. {
  17. // get files from Zoho CRM
  18. v_FileDownloadUrl = "https://www.zohoapis.com/crm/v7/files?id=" + m_FileUpload.get("File_Id__s");
  19. v_FileName = m_FileUpload.get("File_Name__s"); // I am trying to get name and extension in here
  20. f_MyFile = invokeurl
  21. [
  22. url :v_FileDownloadUrl
  23. type :GET
  24. connection:"zoho_crm_connections"
  25. ];
  26. f_MyFile.setParamName("file_data");
  27. f_MyFile.setFileName(v_FileName); // set the file name in here but it doesnt work
  28. l_Files.add(f_MyFile);
  29. }
  30. if(!l_Files.isEmpty())
  31. {
  32. first_file = l_Files.get(0);
  33. // send first file only to Blueray Server
  34. bodyMap = Map();
  35. bodyMap.put("file_data",first_file);
  36. fileResponse = invokeurl
  37. [
  38. url :"https://myAPI.com/file/upload"
  39. type :POST
  40. parameters:bodyMap
  41. ];
  42. file_url = fileResponse.get("file_url");
  43. // update the field in deal module
  44. update = {"Product_Attachment_URL":file_url};
  45. zoho.crm.updateRecord("Deals",DEAL_ID,update);
  46. }
  47. }