diff --git a/modules/Vtiger/models/Record.php b/modules/Vtiger/models/Record.php
index 99dd3d430336cddc49bf7cc6bc305e9b318ad770..90a10f6733cf541456f7f4be02667614d4e663e8 100644
--- a/modules/Vtiger/models/Record.php
+++ b/modules/Vtiger/models/Record.php
@@ -741,5 +741,17 @@ class Vtiger_Record_Model extends Vtiger_Base_Model {
 
 		return array_merge($relatedModuleRecordIds, $directrelatedModuleRecordIds, $indirectrelatedModuleRecordIds);
 	}
+        
+        function getDownloadFileURL($attachmentId = false) {
+            $fileDetails = $this->getFileDetails($attachmentId);
+            if (is_array($fileDetails[0])) {
+                $fileDetails = $fileDetails[0];
+            }
+            if (!empty($fileDetails)) {
+                    return 'index.php?module='. $this->getModuleName() .'&action=DownloadFile&record='. $this->getId() .'&fileid='. $fileDetails['attachmentsid'].'&name='. $fileDetails['name'];
+            } else {
+                    return $this->get('filename');
+            }
+	}
 
 }
diff --git a/packages/vtiger/optional/ModComments.zip b/packages/vtiger/optional/ModComments.zip
index 1145c2fead8c7fb6fa2b10fecba4e952ac72e421..d8bf00828de3834f7b04a685510cc41be2f81b99 100644
Binary files a/packages/vtiger/optional/ModComments.zip and b/packages/vtiger/optional/ModComments.zip differ
diff --git a/pkg/vtiger/modules/ModComments/layouts/v7/modules/ModComments/FilePreview.tpl b/pkg/vtiger/modules/ModComments/layouts/v7/modules/ModComments/FilePreview.tpl
index ae89e62f20f576f970c0035e0ccbdfb1cd5bb6e4..c11c208a7f7f1127c36c32b2b56cdac66e99ea16 100644
--- a/pkg/vtiger/modules/ModComments/layouts/v7/modules/ModComments/FilePreview.tpl
+++ b/pkg/vtiger/modules/ModComments/layouts/v7/modules/ModComments/FilePreview.tpl
@@ -52,7 +52,7 @@
                         {else if $OPENDOCUMENT_FILE_TYPE eq 'yes'}
                             <iframe id="viewer" src="libraries/jquery/Viewer.js/#../../../{$DOWNLOAD_URL}" width="100%" height="100%" allowfullscreen webkitallowfullscreen></iframe>
                         {else if $PDF_FILE_TYPE eq 'yes'}
-                            <iframe id='viewer' src="libraries/jquery/pdfjs/web/viewer.html?file={$SITE_URL}/{$FILE_PATH}" height="100%" width="100%"></iframe>
+                            <iframe id='viewer' src="libraries/jquery/pdfjs/web/viewer.html?file={$SITE_URL}/{$DOWNLOAD_URL|escape:'url'}" height="100%" width="100%"></iframe>
                         {else if $IMAGE_FILE_TYPE eq 'yes'}
                             <div style="overflow:auto;height:100%;width:100%;float:left;background-image: url({$DOWNLOAD_URL});background-color: #EEEEEE;background-position: center 25%;background-repeat: no-repeat;display: block; background-size: contain;"></div>
                         {else if $AUDIO_FILE_TYPE eq 'yes'}
diff --git a/pkg/vtiger/modules/ModComments/modules/ModComments/views/FilePreview.php b/pkg/vtiger/modules/ModComments/modules/ModComments/views/FilePreview.php
index 79081deaea5e78a4ea7be35038ea444715dd6b07..1d058387c138e5f752e123c45546253136f5ac7d 100644
--- a/pkg/vtiger/modules/ModComments/modules/ModComments/views/FilePreview.php
+++ b/pkg/vtiger/modules/ModComments/modules/ModComments/views/FilePreview.php
@@ -48,7 +48,7 @@ class ModComments_FilePreview_View extends Vtiger_IndexAjax_View {
 			}
 		}
 
-		$path = $fileDetails['path'].$fileDetails['attachmentsid'].'_'.$fileDetails['name'];
+		$path = $fileDetails['path'].$fileDetails['attachmentsid'].'_'.$storedFileName;
 		$type = $fileDetails['type'];
 		$contents = $fileContent;
 		$filename = $fileDetails['name'];
@@ -56,11 +56,10 @@ class ModComments_FilePreview_View extends Vtiger_IndexAjax_View {
 		if ($recordModel->get('filename')) {
 			$fileDetails = $recordModel->getFileNameAndDownloadURL($recordId, $attachmentId);
 		}
-
-		if (is_array($fileDetails[0])) {
-			$downloadUrl = $fileDetails[0]['url'];
-			$trimmedFileName = $fileDetails[0]['trimmedFileName'];
-		}
+                if ($recordModel->get('filename')) {
+                    $downloadUrl =  $recordModel->getDownloadFileURL($attachmentId);
+                    $trimmedFileName = $fileDetails[0]['trimmedFileName'];
+                }
 
 		//support for plain/text document
 		$extn = 'txt';