We’ve developed some resources to help you work effectively from home during COVID-19 Click to learn more

GetDocumentStream returns wrong version of document (!!)

Hi,

We are currently building an document app for Appstore and we have ran into a MAJOR issue.

Recreate the issue:

1. Create a document in SuperOffice and open it and write "TEST".
2. Upload the save (webhooks or drag and drop)
3. Open the Document, add for example "UPDATE".
4. Upload the save.
5. Verify that the documents says: "TEST UPDATE".
6. Get the DocumentId and run the following:

                using (var docAgent = new DocumentAgent())
                {
                    var stream = docAgent.GetDocumentStream(request.DocumentId);
                    
                    byte[] bytes;
                    using (var memoryStream = new MemoryStream())
                    {
                        stream.CopyTo(memoryStream);
                        bytes = memoryStream.ToArray();
                    }
                    var MyDocumentBase64 = Convert.ToBase64String(bytes);
                 }

Result: in MyDocumentBase64 is: TEST

No matter how many updates you do to the document the docagent will return the original document.

How can we solve this?
Same issue occours with GetDocumentStreamForEntity.


Regards
Pär Pettersson

RE: GetDocumentStream returns wrong version of document (!!)

Check in the document after update.

 

Check /api/v1/Document/123/lock 

If the document is locked by another user, you won't see the changes until the changes are checked-in.

(This is why the doc dialog has a check-in-on-save option)

  <user> Creates document

  <user> Uploads content

  <user> checks out document

  <user> Uploads more content

  <user> gets more content back

 

It gets trickier when more than one user is involved

  <user> Creates document

  <user> Uploads content

  <user> checks out document

  <user> Uploads "more content" (this updates checked out copy only visible to user.

  <user2> gets "content" back (document at the time it was checked out)

  <user> checks in document (makes changes visible to others)

  <user2> gets "more content" back 

 

Av: Margrethe Romnes 12. des 2018

RE: GetDocumentStream returns wrong version of document (!!)

No, the answer is that you havent released the old stream, and you will read the first stream every time (precily why I don't know but it has to  do woth caching I am sure).

You have to read the stream something like beneath, the different is the stream from the document is in a using() 

FileAsStreamResponse file = new FileAsStreamResponse();

using (DocumentAgent da = new DocumentAgent())
{
    Document doc = da.GetDocument(Request.Id);
    file.FileName = doc.Name;
    using (Stream docstream = da.GetDocumentStream(Request.Id))
    {
        file.FileContent = docstream.ToByteArray();
    }
}

return file;
Av: Martin K. Andersen 12. des 2018

RE: GetDocumentStream returns wrong version of document (!!)

You are correct Martin, it works now.

 

Thank you so much for the input and have a great day!

Regards

Av: Pär Pettersson 16. jan 2019