Save Documents in Zoho Office Integrator

How do I save documents locally using "save_url" method? Any sample codes available?

A "save_url" is a publicly accessible Web hook or a Web URL to which Zoho will push the updated document content from its Office editors (Writer, Sheet, Show) to your storage server.

In order to make use of "save_url" method and save document locally, business embedding our Online Office editors in their Web application should fulfil certain requirements as listed below:
  1. Business need to expose one of the remote server ports - port 443 (HTTPS) or port 80 (HTTP) - from their location, for Zoho Office editors (Writer, Sheet, Show) to push the document data and save it locally.

  2. The "save_url" parameter value specified in the Office Integrator API request should to be a proper domain name and publicly accessible over the web. Example: https://document.zylker.com/save.php

Save_url Sample Code:

Once you are done with editing your document and click "Save", the respective Zoho Office editors (Writer, Sheet, Show) will convert the document to the required format (say docx/xlsx/pptx) as specified in the API request and push the modified content to your storage server mentioned in the "save_url". We have come up with save_url sample codes in different languages (PHP, Java, ASP.NET, etc.) that illustrates how a save_url file should look like.

PHP Sample Code:

Developers who are using PHP programming language for their Zoho Office Integrator solution, can use the below save_url sample code and save the document locally in their own storage servers.

'/DOC_REPOSITORY_FOLDER_PATH/samplefile.docx';
$tmp_filename = $_FILES['content']['tmp_name']; 
$upload_status = move_uploaded_file($tmp_filename, $filepath);
?>           
Code Reference:

$_FILES['content']['tmp_name'] - $_FILES array is where PHP stores all the information about files.
There are two elements of this array - content and tmp_name

content - document content that is uploaded to Zoho editors while doing a HTTP multi-part form POST.
tmp_name - tmp_name contains the path to the temporary file that resides on the Zoho document server. 

move_uploaded_file - Thisfunction moves the temporary file from 
Zoho's document server to the document repository folder path that you provide 
along with the file name and file extension.

Note: Example of doc repository folder path - "/apache/htdocs/zohosave/samplefile.docx" 
or "C:\Zylker\Documents\samplefile.docx"

Java Sample Code
:

In the following example, a sample action (savedoc.do) written using Struts Application will parse, retrieve and save the document content sent from Zoho Office editors (Writer, Sheet, Show) to the folder path of your local storage server specified in the save_url parameter.

package com.Sample;
import java.lang.*;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
//add this jar - commons-fileupload-1.3.3.jarimport org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;

public classSaveUrlServletextendsHttpServlet {
private static final long serialVersionUID = 1L;
private static finalString UPLOAD_DIRECTORY = "upload";
private static final int MEMORY_THRESHOLD   = 1024 * 1024 * 3;  
// 3MBprivate static final int MAX_FILE_SIZE      = 1024 * 1024 * 40;
// 40MBprivate static final int MAX_REQUEST_SIZE   = 1024 * 1024 * 50;
// 50MBpublic void doPost(HttpServletRequest request,
HttpServletResponse response) throwsServletException, IOException {
PrintWriter writer = response.getWriter();
if (!ServletFileUpload.isMultipartContent(request)) {

writer.write("RESPONSE: Form must has enctype=multipart/form-data.");

response.setStatus(response.SC_BAD_REQUEST);
writer.flush();
return;
}
DiskFileItemFactory factory = newDiskFileItemFactory();

factory.setSizeThreshold(MEMORY_THRESHOLD);

factory.setRepository(newFile(System.getProperty("java.io.tmpdir")));

ServletFileUpload upload = newServletFileUpload(factory);
upload.setFileSizeMax(MAX_FILE_SIZE);
upload.setSizeMax(MAX_REQUEST_SIZE);
String uploadPath = getServletContext().getRealPath("")+ File.separator + UPLOAD_DIRECTORY;
File uploadDir = newFile(uploadPath);
if (!uploadDir.exists()) {
 uploadDir.mkdir();
}

try {
List formItems = upload.parseRequest(request);
System.out.println("Form Items Values   >>>   "+formItems);
if (formItems != null && formItems.size() > 0) {

for (FileItem item : formItems) {
System.out.println("Field Name:"+item.getFieldName());
if(!item.isFormField()){
if (item.getFieldName().equalsIgnoreCase("content")){
String  fileName = newFile(item.getName()).getName();
String filePath = uploadPath + "/" + fileName;
File storeFile = newFile(filePath);
item.write(storeFile);
}
}else{
byte[] fieldVal;
if (item.getFieldName().equalsIgnoreCase("filename")){
fieldVal = item.get();
String fileNameValue = newString(fieldVal);
System.out.println(item.getFieldName()+" value: "+fileNameValue);
}else if(item.getFieldName().equalsIgnoreCase("id")){
fieldVal = item.get();
String idValue = newString(fieldVal);
System.out.println(item.getFieldName()+" value: "+idValue);
}
else if(item.getFieldName().equalsIgnoreCase("format")){
fieldVal = item.get();
String formatValue = newString(fieldVal);
System.out.println(item.getFieldName()+" value: "+formatValue);
}
}
}
response.setStatus(response.SC_OK);
writer.write("Document Saved Successfully!");
}
}catch (Exception ex) {
response.setStatus(response.SC_BAD_REQUEST);

writer.write("RESPONSE:Document save fails");
// For Custom message showing in Zoho editor

}
}
public void doGet(HttpServletRequest request,
HttpServletResponse response) throwsServletException, IOException {
PrintWriter writer = response.getWriter();
writer.write("Not Allowed");
response.setStatus(response.SC_BAD_REQUEST);
}
}

ASP.NET Sample Code:

Similarly, the save_url sample file in ASP.NET will look like the one below:

'this is page load event 

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load'

declaring variable - object declared to get the content of uploaded file

Dim m_objFile As HttpPostedFileDim filename As String'here we are getting the requested file content 

 m_objFile = Request.Files("content")'

 Here we are getting the exact file name that was sent during HTTP POST form submit

filename = Request.QueryString("filename")

'saving the file in document repository folder path

Request.Files("content").SaveAs("C:\inetpub\" + filename) 

End Sub

Note: Any text inside the sample code preceded by single quotes (') is a comment in ASP.Net.


    Zoho CRM Training Programs

    Learn how to use the best tools for sales force automation and better customer engagement from Zoho's implementation specialists.

    Zoho CRM Training
      Redefine the way you work
      with Zoho Workplace

        Zoho DataPrep Personalized Demo

        If you'd like a personalized walk-through of our data preparation tool, please request a demo and we'll be happy to show you how to get the best out of Zoho DataPrep.

        Zoho CRM Training

          Create, share, and deliver

          beautiful slides from anywhere.

          Get Started Now


            Zoho Sign now offers specialized one-on-one training for both administrators and developers.

            BOOK A SESSION





                        Still can't find what you're looking for?

                        Write to us:  support@zohoforms.com


                              




                            

                              Zoho Marketing Automation

                                Zoho Sheet Resources

                                 




                                    Zoho Forms Resources


                                      Secure your business
                                      communication with Zoho Mail


                                      Mail on the move with
                                      Zoho Mail mobile application

                                        Stay on top of your schedule
                                        at all times


                                        Carry your calendar with you
                                        Anytime, anywhere




                                              Zoho Sign Resources

                                                Sign, Paperless!

                                                Sign and send business documents on the go!

                                                Get Started Now


                                                    Zoho SalesIQ Resources



                                                        Zoho TeamInbox Resources



                                                                Zoho DataPrep Resources



                                                                  Zoho DataPrep Demo

                                                                  Get a personalized demo or POC

                                                                  REGISTER NOW


                                                                    Design. Discuss. Deliver.

                                                                    Create visually engaging stories with Zoho Show.

                                                                    Get Started Now











                                                                                          • Related Articles

                                                                                          • How does document collaboration work in Office Integrator?

                                                                                            Zoho Office Integrator supports real-time document collaboration, and multiple users can be invited and everyone can contribute to the document with their edits at the same time.  To further enhance user productivity and foster teamwork, business can ...
                                                                                          • Office Integrator - Overview

                                                                                            Getting Started with Zoho Office Integrator Zoho Office Integrator is an online and cloud-based system which is used for the integration of its significant document editors – Sheet, Writer, and Show with third-party web applications and services. ...
                                                                                          • HIPPA Compliance with Zoho Office Integrator

                                                                                             INTRODUCTION  The Health Insurance Portability and Accountability Act (including the Privacy Rule, Security Rule, Breach notification Rule, and Health Information Technology for Economic and Clinical Health Act) ("HIPAA"), requires Covered Entities ...
                                                                                          • How do I edit documents in Zoho Writer? Any sample codes?

                                                                                            To edit an existing document from your web application, you need to make use of Zoho Writer's Edit Document API. HTML Sample Code: <form method="POST" action=" https://writer.zoho.com/writer/officeapi/v1/document" enctype="multipart/form-data" ...
                                                                                          • How do I compare two documents in Zoho Writer? Any sample codes?

                                                                                            To compare two versions of a document, you need to make use of Zoho Writer's Comparison API. HTML Sample Code: <form method="POST" action="https://writer.zoho.com/writer/officeapi/v1/document/compare" enctype="multipart/form-data" ...
                                                                                          Wherever you are is as good as
                                                                                          your workplace

                                                                                            Resources

                                                                                            Videos

                                                                                            Watch comprehensive videos on features and other important topics that will help you master Zoho CRM.



                                                                                            eBooks

                                                                                            Download free eBooks and access a range of topics to get deeper insight on successfully using Zoho CRM.



                                                                                            Webinars

                                                                                            Sign up for our webinars and learn the Zoho CRM basics, from customization to sales force automation and more.



                                                                                            CRM Tips

                                                                                            Make the most of Zoho CRM with these useful tips.



                                                                                              Zoho Show Resources