Auto save document in document editor in Vue Document editor component

23 Mar 20237 minutes to read

In this article, we are going to see how to autosave the document in AWS S3. You can automatically save the edited content in regular intervals of time. It helps reduce the risk of data loss by saving an open document automatically at customized intervals.

The following example illustrates how to auto save the document in AWS S3.

  • In the client-side, using content change event, we can automatically save the edited content in regular intervals of time. Based on contentChanged boolean, the document send as Docx format to server-side using saveAsBlob method.

          <div id="app">
            <ejs-documenteditorcontainer ref='container' :serviceUrl='serviceUrl' v-on:created="onCreated" v-on:contentChange="contentChangeEvent" height="590px" id='container' :enableToolbar='true'></ejs-documenteditorcontainer>
        import Vue from 'vue';
        import { DocumentEditorContainerPlugin, DocumentEditorContainerComponent,Toolbar} from '@syncfusion/ej2-vue-documenteditor';
        export default {
          data() {
            return { serviceUrl:'',
          provide: {
            //Inject require modules.
            DocumentEditorContainer: [Toolbar]
          methods: {
            contentChangeEvent: function () {
              this.contentChanged = true;
            onCreated: function () {
              setInterval(() => {
                if (this.contentChanged) {
                  //You can save the document as below
                    .then((blob) => {
                      console.log('Saved sucessfully');
                      let exportedDocument = blob;
                      //Now, save the document where ever you want.
                      let formData = new FormData();
                      formData.append('fileName', 'sample.docx');
                      formData.append('data', exportedDocument);
                      /* tslint:disable */
                      var req = new XMLHttpRequest();
                      // Replace your running Url here
                      req.onreadystatechange = () => {
                        if (req.readyState === 4) {
                          if (req.status === 200 || req.status === 304) {
                            console.log('Saved sucessfully');
                  this.contentChanged = false;
              }, 1000);
  • In server-side, configure the access key and secret key in web.config file and register profile in startup.cs.

    In `web.config`, add key like below format:
        <add key="AWSProfileName" value="sync_development" />
        <add key="AWSAccessKey" value="" />
        <add key="AWSSecretKey" value="" />
    In `startup.cs`, register profile in below format:
    Amazon.Util.ProfileManager.RegisterProfile("sync_development","", "");
    • In server-side, Receives the stream content from client-side and process it to save the document in aws s3. Add Web API in controller file like below to save the document in aws s3.

        public string SaveToS3()
            IFormFile file = HttpContext.Request.Form.Files[0];
            Stream stream = new MemoryStream();
            UploadFileStreamToS3(stream, "documenteditor", "", "GettingStarted.docx");
            return "Sucess";
        public bool UploadFileStreamToS3(System.IO.Stream localFilePath, string bucketName, string subDirectoryInBucket, string fileNameInS3)
            AWSCredentials credentials = new StoredProfileAWSCredentials("sync_development");
            IAmazonS3 client = new AmazonS3Client(credentials, Amazon.RegionEndpoint.USEast1);
            TransferUtility utility = new TransferUtility(client);
            TransferUtilityUploadRequest request = new TransferUtilityUploadRequest();
            if (subDirectoryInBucket == "" || subDirectoryInBucket == null)
        request.BucketName = bucketName; //no subdirectory just bucket name  
            {   // subdirectory and bucket name  
        request.BucketName = bucketName + @"/" + subDirectoryInBucket;
            request.Key = fileNameInS3; //file name up in S3  
            request.InputStream = localFilePath;
            utility.Upload(request); //commensing the transfer  
            return true; //indicate that the file was sent  

Get the complete working sample in this link.