[DocumentHelper.GetAttachment]: Attachment with given GUID not found in page version

Pankaj Meena asked on March 18, 2021 09:35

I was trying to create attachments using the REST APIs,followed the steps given in the kentico document https://docs.xperience.io/k12sp/integrating-3rd-party-systems/kentico-rest-service/manipulating-data-using-rest

but after few minutes attachment record in cms_attachment table is deleted automatically. I am not sure why it is happening. But when I am trying to access https://localhost:44317/getattachment/B3B22BDC-1382-40E0-8856-2B202DC7DD16/sd.aspx url it gives me [DocumentHelper.GetAttachment]: Attachment with given GUID not found in page version error

Recent Answers


Dmitry Bastron answered on March 18, 2021 09:56

Hi Pankaj,

Do you have workflow enabled for the pages you are trying to add attachments? Also please check in the database whether you see this attachment guid in one of the following tables: CMS_Attachment or CMS_AttachmentHistory

0 votesVote for this answer Mark as a Correct answer

Pankaj Meena answered on March 18, 2021 10:56

Q - Do you have workflow enabled for the pages you are trying to add attachments?

A - Yes workflow is enabled for the pages.

Q - Also please check in the database whether you see this attachment guid in one of the following tables: CMS_Attachment or CMS_AttachmentHistory

A - When I added the attachment It was in CMS_Attachment table but after publishing the document it got removed from CMS_Attachment table.

Below are the steps:-

1) Creating attachment via rest api 2) Creating a new CMS.File with FileAttachment set as AttachmentGUID(from above response)

curl --location --request POST 'https://localhost:44317/rest/content/currentsite/en-us/document/Resources/Image' \
--header 'Authorization: Basic YWRtaW46cGFzc3dvcmQ=' \
--header 'Content-Type: application/xml' \
--header 'Cookie: CMSPreferredCulture=en-US; ASP.NET_SessionId=qinviejnknirmpcgfsljib14' \
--data-raw '<CMS_File>
  <NodeClassID>1685</NodeClassID>
  <!-- <NodeParentID>14833</NodeParentID> -->
  <DocumentExtensions>.png</DocumentExtensions>
  <DocumentType>.png</DocumentType>
  <FileName>cs</FileName>
  <FileAttachment>f494ca50-0de7-4c1b-84f1-5308667937ba</FileAttachment> <!-- Insert the GUID of the appropriate attachment object -->
</CMS_File>'

3) Updating the DocumentID(response from step 2) in newly created attachment

curl --location --request PUT 'https://localhost:44317/rest/cms.attachment/f494ca50-0de7-4c1b-84f1-5308667937ba' \
--header 'Authorization: Basic YWRtaW46cGFzc3dvcmQ=' \
--header 'Content-Type: application/xml' \
--header 'Cookie: CMSPreferredCulture=en-US; ASP.NET_SessionId=qinviejnknirmpcgfsljib14' \
--data-raw '<CMS_Attachment>
  <AttachmentDocumentID>12500</AttachmentDocumentID>
</CMS_Attachment>' 

4) Pubishing the new created CMS.File

0 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on March 18, 2021 12:16

On the last step, did you publish an attachment file or page or both? How did you do the publish: via REST API, via API in the code or manually?

Also, when you create an attachment, do you add it for existing published page, or create a draft page and assign attachment to it? If you can outline the wider flow of actions you are performing this would be helpful.

0 votesVote for this answer Mark as a Correct answer

Pankaj Meena answered on March 18, 2021 13:28

Q- On the last step, did you publish an attachment file or page or both? How did you do the publish: via REST API, via API in the code or manually?'

A- We are publishing the CMS.File manually on the last step.

Q- Also, when you create an attachment, do you add it for existing published page, or create a draft page and assign attachment to it?

A- create a draft page and assign attachment to it

1) Creating attachment via rest api

2) Creating a new CMS.File with FileAttachment field set as AttachmentGUID(from above response) via rest api

3) Updating the DocumentID(response from step 2) in newly created attachment via rest api

4) Pubishing the newly created CMS.File manually.

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on March 19, 2021 11:05

Where are you storing the files? File system or database or both? For testing I would try to disable workflows to see if the image persists. If yes, then it will indicate version history inconsistencies and probably you are overwriting page version with attachment with another version without attachment. The example in the docs is a sample not considering the workflows. If you need to use workflows, you need to ensure you are inserting the attachment into appropriate version of the page (latest edited version vs. latest published version).

1 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on March 19, 2021 11:28

Hi Pankaj,

Ok, workflow makes things more complicated as you can imagine. First of all, let me start with a little explanation. When you enable workflow for pages with attachments, CMS starts tracking versions of both separately. Document versions (including draft and unpublished) are stored in CMS_VersionHistory table, attachment versions - in CMS_AttachmentHistory, and there is a binding table between these two - CMS_VersionAttachment (refer to docs).

Now, what happens in CMS under the hood when you create new CMS.File under workflow:

  • Admin clicks "+" icon and new CMS.File dialog appears
  • Admin selects file to upload, but not yet clicked "Save" button
  • CMS in the meantime creates a temporary attachment (cms.temporaryattachment object) and generates attachmentGuid for it
  • Admin clicks "Save", then:
    • CMS creates a draft CMS.File document version (cms.versionhistory object)
    • Copies temporary attachment into attachment version (cms.attachmenthistory object), assigns it DocumentID of draft CMS.File to it, and deletes temporary attachment
    • Creates a record to connect attachment version and document version (cms.versionattachment object)

In theory, you should replicate this process via REST API:

  1. Create cms.temporaryattachment object, and record returned attachmentGuid
  2. Create CMS.File page with this attachmentGuid referenced, record returned DocumentId and DocumentCheckedOutVersionHistoryID
  3. Create cms.attachmenthistory object, similar to temporary attachment, with the same attachmentGuid and AttachmentDocumentId = DocumentId from the previous request; record returned AttachmentHistoryID
  4. Delete cms.temporaryattachment object
  5. Create cms.versionattachment object with VersionHistoryId = DocumentCheckedOutVersionHistoryID and AttachmentHistoryId = AttachmentHistoryID

One more thing to note, temporary attachment is only needed to generate a unique and consistent attachmentGuid. If you can just generate this new guid outside of Kentico, you can skip steps 1 and 3. I've just tested it locally and it seems to be working fine.

2 votesVote for this answer Mark as a Correct answer

Pankaj Meena answered on March 19, 2021 13:08

@Juraj Ondrus
Q- For testing I would try to disable workflows to see if the image persists. If yes, then it will indicate version history inconsistencies and probably you are overwriting page version with attachment with another version without attachment.

A-You are right @Juraj, It is working fine after I disabled the workflows.

Q- If you need to use workflows, you need to ensure you are inserting the attachment into appropriate version of the page (latest edited version vs. latest published version).

A- I understood what you are saying (inserting the attachment to a valid document verison) but not sure how I am gonna do it in REST API.

0 votesVote for this answer Mark as a Correct answer

Pankaj Meena answered on March 21, 2021 00:04

@Dmitry Bastron

I was trying to replicate your instructions using REST APIs but getting below error

CURL:-

curl --location --request POST 'https://localhost:44317/rest/cms.attachmenthistory/currentsite' \
--header 'Authorization: Basic YWRtaW46cGFzc3dvcmQ=' \
--header 'Content-Type: application/xml' \
--header 'Cookie: CMSPreferredCulture=en-US; ASP.NET_SessionId=mjv5bc5lu0x4ok1hcqkzzwwh' \
--data-raw '<CMS_AttachmentHistory>
  <AttachmentName>vikasHMark2photo.png</AttachmentName>
  <AttachmentExtension>.png</AttachmentExtension>
  <AttachmentSize>3789</AttachmentSize>
  <AttachmentImageWidth>629</AttachmentImageWidth>
  <AttachmentImageHeight>280</AttachmentImageHeight>
  <AttachmentMimeType>image/png</AttachmentMimeType>
  <AttachmentGuid>76cc42af-0655-41a2-a87e-581e343bfb70</AttachmentGuid>
  <AttachmentDocumentID>12558</AttachmentDocumentID>
  <AttachmentGuid>0a4548f3-cd11-4d85-a32b-cc897d0a94a4</AttachmentGuid>
  <AttachmentBinary>iVBORw0KGgoAAAANSUhEUgAAAnUAAAEYCAIAAAC1F5caAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAA5iSURBVHhe7d1tQuJIF4bhd10uyPW4GjfjYuYNSPcocJJK1VMQx+v6N91DSOXj3Eij/u8fACBNXwEgT18BIE9fASBPXwEgT18BIE9fASBPXwEgT18BIE9fASBPXwEgT18BIE9fASBPXwEgT18BIE9fASBPXwEgT18BIE9fASBPXwEgT18BIE9fASBPXwEgT18BIE9fASBPXwEgT18BIE9fASBPXwEgT18BIE9fASBPXwEgT18BIE9fASBPXwEgT18BIE9fASBPXwEgT18BIE9fASBPXwEgT18BIE9fASBPXwEgT18BIE9fASBPXwEgT18BIE9fASBPXwEgT18BIE9fASBPXwEgT18BIE9fASBPXwEgT18BIE9fASBPXwEgT18BIE9fASBPXwEgT18BIE9fASBPXwEgT18BIE9fASBPXwEgT18BIE9fASBPXwEgT18BIE9fASBPXwEgT18BIE9fASBPXwEgT18BIE9fASBPXwEgT18BIE9fASBPXwEgT18BIE9fASBPXwEgT18BIE9fASBPXwEgT18BIE9fASBPXwEgT18BIE9fASBPXwEgT18BIE9fASBPXwEgT18BIE9fASBPXwEgT18BIE9fASBPXwEgT18BIE9fASBPXwEgT18B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2fWypPZfxT8s3Og5yHPO17SrYJ+1ayYodBP/QPrKc7SN0uCdufZV2rhj97VP+8HPLWrexO88wnPO17SrYJd5B/vKrw2svvIkLTd3+L48wvCeN1nb33NvsWuHootafb+6z8C/ss85X/Ougj2yV8yKB6/rOPSVZ9mu3YSXvVu/jq3Pjvkxc7Km5uXuHMUX9bH9q2lbDbT1RF8DHryu49BXnmYrsNPeVWr4HEyr3d8OM3myji6t79t7pixq64PA2wbTevZf7uvWDRjj/WF4vPMIvdOD08dXxkfjhpaPmxaW3Xvr/DbT5auGt+slx1fbs7S+sv4xbVFdZ2lsLVemLO12VcuTvD08Qw8p7K/96lVf4TTCl86fP4Z6b5Kf/3j5689PFl8e80Ocl3b+6PPtyi7rWpb1I1a1LOXPSm5P0udSfsxa+CX0FQDy9BUA8vQVAPL0FQDy9BUA8vQVAPL0FQDy9BUA8vQVAPL0FQDy9BUA8vQVAPL0FQDy9BUA8vQVAPL0FQDy9BUA8vQVAPL0FQDy9BUA8vQVAPL0FQDy9BUA8vQVAPL0FQDy9BUA8vQVAPL0FQDy9BUA8vQVAPL0FQDy9BUA8vQVAPL0FQDy9BUA8vQVAPL0FQDy9BUA8vQVAPL0FQDy9BUA8vQVAPL0FQDy9BUA8vQVAPL0FQDy9BUA8vQVAPL0FQDy9BUA8vQVAPL0FQDy9BUA8vQVAPL0FQDy9BUA8vQVAPL0FQDy9BUA8vQVAPL0FQDy9BUA8vQVAPL0FQDy9BUA8vQVAPL0FQDy9BUA8vQVAPL0FQDy9BUA8vQVAPL0FQDy9BUA8vQVAPL0FQDy9BUA8vQVAPL0FQDy9BUA8vQVAPL0FQDy9BUA8vQVAPL0FQDy9BUA8vQVAPL0FQDy9BUA8vQVAPL0FQDy9BUA8vQVAPL0FQDy9BUA8vQVAPL0FQDS/vnn/4tQFR7zy+2CAAAAAElFTkSuQmCC</AttachmentBinary> <!-- Insert base 64 encoded binary data -->
</CMS_AttachmentHistory>'





Message:
[DataConnection.HandleError]:

Query:
INSERT INTO CMS_AttachmentHistory ([AttachmentName], [AttachmentExtension], [AttachmentSize], [AttachmentMimeType], [AttachmentBinary], [AttachmentImageWidth], [AttachmentImageHeight], [AttachmentDocumentID], [AttachmentGUID], [AttachmentIsUnsorted], [AttachmentOrder], [AttachmentGroupGUID], [AttachmentHash], [AttachmentTitle], [AttachmentDescription], [AttachmentCustomData], [AttachmentLastModified], [AttachmentHistoryGUID], [AttachmentSiteID], [AttachmentSearchContent], [AttachmentVariantDefinitionIdentifier], [AttachmentVariantParentID])
VALUES (@AttachmentName, @AttachmentExtension, @AttachmentSize, @AttachmentMimeType, @AttachmentBinary, @AttachmentImageWidth, @AttachmentImageHeight, @AttachmentDocumentID, @AttachmentGUID, @AttachmentIsUnsorted, @AttachmentOrder, @AttachmentGroupGUID, @AttachmentHash, @AttachmentTitle, @AttachmentDescription, @AttachmentCustomData, @AttachmentLastModified, @AttachmentHistoryGUID, @AttachmentSiteID, @AttachmentSearchContent, @AttachmentVariantDefinitionIdentifier, @AttachmentVariantParentID);

SELECT SCOPE_IDENTITY() AS [ID]

Caused exception:
Cannot insert the value NULL into column 'AttachmentName', table 'OP_NOF_Kentico12.dbo.CMS_AttachmentHistory'; column does not allow nulls. INSERT fails.
The statement has been terminated.


Exception type: System.Exception
Stack trace:
at CMS.DataEngine.AbstractDataConnection.HandleError(String queryText, Exception ex)
at CMS.DataEngine.AbstractDataConnection.ExecuteQuery(String queryText, QueryDataParameters queryParams, QueryTypeEnum queryType, Boolean requiresTransaction)
at CMS.DataEngine.AbstractDataConnection.CMS.DataEngine.IDataConnection.ExecuteQuery(String queryText, QueryDataParameters queryParams, QueryTypeEnum queryType, Boolean requiresTransaction)
at CMS.DataEngine.GeneralConnection.RunQuery(QueryParameters query)
at CMS.DataEngine.GeneralConnection.RunQueryWithRetry(QueryParameters query, Int32 retryCount)
at CMS.DataEngine.GeneralConnection.ExecuteQuery(QueryParameters query)
at CMS.DataEngine.GeneralConnection.ExecuteQuery(QueryParameters query, Int32& totalRecords)
at CMS.DataEngine.DataQueryBase`1.GetDataFromDBInternal()
at CMS.DataEngine.DataQueryBase`1.GetDataFromDB()
at CMS.DataEngine.DataQueryBase`1.GetData()
at CMS.DataEngine.SimpleDataClass.Insert(Boolean initId)
at CMS.DataEngine.AbstractInfoBase`1.InsertDataInternal()
at CMS.DataEngine.AbstractInfoBase`1.InsertData()
at CMS.DataEngine.AbstractInfoBase`1.GeneralizedInfoWrapper.InsertData()
at CMS.DataEngine.AbstractInfoProvider`3.SetInfo(TInfo info)
at CMS.DocumentEngine.AttachmentHistoryInfoProvider.SetInfo(AttachmentHistoryInfo info)
at CMS.DocumentEngine.AttachmentHistoryInfo.SetObject()
at CMS.DataEngine.BaseInfo.SubmitChanges(Boolean withCollections)
at CMS.WebServices.BaseRESTService.SetObjectInternal(GeneralizedInfo info, String objectType, Stream stream, Boolean isCreate, String siteName)
at CMS.WebServices.RESTService.CreateCurrentSiteObject(String objectType, Stream stream)
at SyncInvokeCreateCurrentSiteObject(Object , Object[] , Object[] )
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
at CMS.WebServices.RESTSecurityInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)

Message: Cannot insert the value NULL into column 'AttachmentName', table 'OP_NOF_Kentico12.dbo.CMS_AttachmentHistory'; column does not allow nulls. INSERT fails.
The statement has been terminated.

Exception type: System.Data.SqlClient.SqlException
Stack trace:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
at CMS.DataEngine.AbstractDataConnection.ExecuteQuery(String queryText, QueryDataParameters queryParams, QueryTypeEnum queryType, Boolean requiresTransaction)
0 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on March 22, 2021 10:20

Hi Pankaj,

Your example works on my local installation with no issues.

What version of CMS are you using and what hotfix? Have you tried to update to the latest hotfix? There could also be a problem with your installation. I'd recommend testing it on clean installation as well.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.