diff --git a/include/Webservices/DataTransform.php b/include/Webservices/DataTransform.php
index 36c66b535d4e96f8715f92807cd65f30ebe4c4ac..832c69b9cf85a7e56e7392a5acc627ce4e0de29e 100644
--- a/include/Webservices/DataTransform.php
+++ b/include/Webservices/DataTransform.php
@@ -52,6 +52,7 @@
 
 			$newRow = DataTransform::sanitizeReferences($newRow,$meta);
 			$newRow = DataTransform::sanitizeOwnerFields($newRow,$meta,$t);
+            $newRow = DataTransform::sanitizeFileFieldsForIds($newRow, $meta);
 			$newRow = DataTransform::sanitizeFields($newRow,$meta);
 			return $newRow;
 		}
@@ -255,6 +256,37 @@
 			}
 			return $row;
 		}
+        
+        /**
+         * Function to attach the image/file ids in retrieve/query operations
+         * @param type $row
+         * @param type $meta
+         * @return <array>
+         */
+        static function sanitizeFileFieldsForIds($row, $meta) {
+            $moduleFields = $meta->getModuleFields();
+            $supportedUITypes = array(61, 69, 28); //file and image uitypes
+            $attachmentIds = array();
+            foreach ($moduleFields as $fieldName => $fieldObj) {
+                if (in_array($fieldObj->getUIType(), $supportedUITypes)) {
+                    //while doing retrieve operation we have record_id and on query operation we have id.
+                    $id = $row['record_id'] ? $row['record_id'] : $row['id'];
+                    $ids = Vtiger_Functions::getAttachmentIds($id, $meta->getEntityId());
+                if($ids) {
+                        foreach($ids as $id){
+                            array_push($attachmentIds, $id);
+                        }
+                    }
+                    break;
+                }
+            }
+
+            if (!empty($attachmentIds)){
+                $row['imageattachmentids'] = implode(',', $attachmentIds);
+            }
+
+            return $row;
+        }
 
 		function sanitizeDateFieldsForInsert($row,$meta){
 			global $current_user;
diff --git a/include/Webservices/Utils.php b/include/Webservices/Utils.php
index 3939b5a5e7b01e3a29f41d977d5c37a022cab6a1..cd0d3cc580fb82ddfbdda0142725bf43e4b57692 100644
--- a/include/Webservices/Utils.php
+++ b/include/Webservices/Utils.php
@@ -1285,4 +1285,36 @@ function vtws_isDuplicatesAllowed($webserviceObject){
 	return $allowed;
 }
 
+function vtws_filedetails($fileData){
+    $fileDetails = array();
+    if(!empty($fileData)) {
+        $fileName = $fileData['name'];
+        $fileType = $fileData['type'];
+        $fileName = html_entity_decode($fileName, ENT_QUOTES, vglobal('default_charset'));
+        $filenamewithpath = $fileData['path'].'_'.$fileData['encName'];
+        $filesize = filesize($filenamewithpath);
+        $fileDetails['fileid'] = $fileData['attachmentsid'];
+        $fileDetails['filename'] = $fileName;
+        $fileDetails['filetype'] = $fileType;
+        $fileDetails['filesize'] = $filesize;
+        $fileDetails['filecontents'] = base64_encode(file_get_contents($filenamewithpath));
+    }
+    return $fileDetails;
+}
+
+function vtws_getAttachmentRecordId($attachmentId) {
+    $db = PearDatabase::getInstance();
+    $crmid = false;
+    if(!empty($attachmentId)) {
+        $query = "SELECT vtiger_seattachmentsrel.crmid FROM vtiger_seattachmentsrel "
+                . "INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid=vtiger_seattachmentsrel.crmid"
+                . " WHERE vtiger_seattachmentsrel.attachmentsid = ? AND vtiger_crmentity.deleted = ?";
+        $result = $db->pquery($query, array($attachmentId, 0));
+        
+        if ($db->num_rows($result) > 0) {
+            $crmid = $db->query_result($result, 0, 'crmid');
+        }
+    }
+    return $crmid;
+}
 ?>
\ No newline at end of file
diff --git a/include/Webservices/VtigerModuleOperation.php b/include/Webservices/VtigerModuleOperation.php
index 0ee1ca18fa546b1348516c4f2451f512bd654630..780eb7902d353f7620a04dfcb113358099cff901 100644
--- a/include/Webservices/VtigerModuleOperation.php
+++ b/include/Webservices/VtigerModuleOperation.php
@@ -299,6 +299,34 @@ class VtigerModuleOperation extends WebserviceEntityOperation {
 		$moduleFields = $this->meta->getModuleFields();
 		return $this->getDescribeFieldArray($moduleFields[$fieldName]);
 	}
+    
+    /**
+     * Function to get the file content
+     * @param type $id
+     * @return type
+     * @throws WebServiceException
+     */
+    public function file_retrieve($crmid, $elementType, $attachmentId=false){
+		$ids = vtws_getIdComponents($crmid);
+		$crmid = $ids[1];
+        $recordModel = Vtiger_Record_Model::getInstanceById($crmid, $elementType);
+        if($attachmentId) {
+            $attachmentDetails = $recordModel->getFileDetails($attachmentId);
+        } else {
+            $attachmentDetails = $recordModel->getFileDetails();
+        }
+        $fileDetails = array();
+        if (!empty ($attachmentDetails)) {
+            if(is_array(current(($attachmentDetails)))) {
+                foreach ($attachmentDetails as $key => $attachment) {
+                    $fileDetails[$key] = vtws_filedetails($attachment);
+                }
+            } else if(is_array($attachmentDetails)){
+                $fileDetails[] = vtws_filedetails($attachmentDetails);
+            }
+        }
+        return $fileDetails;
+	}
 	
 }
 ?>
diff --git a/modules/Migration/schema/720_to_721.php b/modules/Migration/schema/720_to_721.php
index 002d1612b9de4b4b9b9def55b50479173ddc6042..11b615637215830b60dfe8bb24d0588d8b75b584 100644
--- a/modules/Migration/schema/720_to_721.php
+++ b/modules/Migration/schema/720_to_721.php
@@ -211,5 +211,18 @@ if (defined('VTIGER_UPGRADE')) {
         $portalLoginTemplateRecord->save();
         $portalLoginTemplateId = $portalLoginTemplateRecord->getId();
         echo "Customer portal login template created.<br>";
+        
+        //#1278 - registered new webservice api
+		$operationName = 'files_retrieve';
+		$handler_path = 'include/Webservices/FileRetrieve.php';
+		$handler_method = 'vtws_file_retrieve';
+		$operation_type = 'GET';
+
+		$result = $db->pquery("SELECT 1 FROM vtiger_ws_operation WHERE name = ?", array($operationName));
+		if(!$db->num_rows($result)) {
+		    $operationId = vtws_addWebserviceOperation($operationName, $handler_path, $handler_method, $operation_type);
+		    vtws_addWebserviceOperationParam($operationId, 'id', 'string', 1);
+		}
+		//4537596 - END
     }
 }
\ No newline at end of file
diff --git a/vtlib/Vtiger/Functions.php b/vtlib/Vtiger/Functions.php
index 1062bdeb64aa45c9251eb53b2c9729569e63b8f0..9a2eb9057833b7a82029a8e4eb081e3e56ac0bef 100644
--- a/vtlib/Vtiger/Functions.php
+++ b/vtlib/Vtiger/Functions.php
@@ -1557,4 +1557,28 @@ class Vtiger_Functions {
 		}
 		return $publicUrl;
 	}
+    
+    /**
+     * Function to get the attachmentsid to given crmid
+     * @param type $crmid
+     * @param type $webaservice entity id
+     * @return <Array> 
+     */
+    static function getAttachmentIds($crmid, $WsEntityId) {
+        $adb = PearDatabase::getInstance();
+        $attachmentIds = false;
+        if(!empty($crmid)) {
+            $query = "SELECT attachmentsid FROM vtiger_seattachmentsrel WHERE crmid = ?";
+            $result = $adb->pquery($query, array($crmid));
+            $noofrows = $adb->num_rows($result);
+            if ($adb->num_rows($result) > 1) {
+                for ($i = 0; $i < $noofrows; $i++) {
+                    $attachmentIds[] = vtws_getId($WsEntityId,$adb->query_result($result, $i, 'attachmentsid'));
+                }
+            } else if($adb->num_rows($result) > 0 && $adb->num_rows($result) == 1){
+                $attachmentIds[] = vtws_getId($WsEntityId, $adb->query_result($result, 0, 'attachmentsid'));
+            }
+        }
+        return $attachmentIds;
+    }
 }