Can't upload file to Zoho Docs using API

Can't upload file to Zoho Docs using API

    Hi

    I am using the free version of Zoho Docs and trying to upload a file into the root folder using PHP and the Docs API.

    My source code is as below:

    1. <?php
    2. $cipher = 'rsa_aes_128_sha';
    3. $AUTHTOKEN=" .... ";
    4. $path=" ... ";
    5. $filename=" ... ";

    6. $url = "https://apidocs.zoho.com/files/v1/upload?authtoken=".$AUTHTOKEN."&scope=docsapi";

    7. $fields = array(
    8.             'filename' => $filename,
    9.             'content' => file_get_contents($path."/".$filename)
    10.         );

    11. $ch = curl_init();

    12. $query = http_build_query($fields);

    13. curl_setopt($ch, CURLOPT_POST, TRUE);
    14. curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
    15. curl_setopt($ch, CURLOPT_URL, $url);
    16. curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, $cipher);
    17. curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

    18. $result .= curl_exec($ch);
    19. echo $result;
    20. curl_close($ch);
    21. ?>

    The result is sometimes a properly formed response which says 'Invalid URL' and sometimes a bizarre string that just says:
    1. <!--$Id$ -->

    The URL format appears to match that shown in the API specification. There are some other possible parameters, but these are clearly stated to be optional.

    I have checked that the filename and path are correct, the file has proper permissions and the file contents are being read okay, and query string being constructed properly. The file size is well under the maximum 100M. Other Docs API functions work okay with the same AuthToken.

    What might be going wrong with the file upload?

      Access your files securely from anywhere

          Zoho Developer Community




                                    Zoho Desk Resources

                                    • Desk Community Learning Series


                                    • Digest


                                    • Functions


                                    • Meetups


                                    • Kbase


                                    • Resources


                                    • Glossary


                                    • Desk Marketplace


                                    • MVP Corner


                                    • Word of the Day



                                        Zoho Marketing Automation
                                                • Sticky Posts

                                                • Deprecation of certain URL patterns for published Zoho Writer documents

                                                  Hi Zoho Writer users! We'd like to let you know that we have deprecated certain URL patterns for published and embedded documents in Zoho Writer due to security reasons. If the published or embedded documents are in any of these URL patterns, then their
                                                • [Announcement] Insert image from URL changes in Zoho Writer

                                                  Hi Zoho Writer users! We'd like to let you know that we've changed the behavior of the Insert image from URL option in Zoho Writer for security reasons. Earlier behavior Once you inserted an image URL in a Writer document, the image would be fetched from
                                                • Introducing plagiarism checker in Zoho Writer

                                                  Zia, Zoho Writer's AI-driven writing assistant, now highlights plagiarized and duplicated content in addition to offering contextual grammar and writing suggestions to help you write clearly and concisely in English. Zoho Writer's plagiarism reports Here
                                                • [Important announcement] Impact of Google's new email guidelines for Zoho Writer automation users

                                                  Hi users, Google has recently announced new guidelines for sending emails to Gmail and other Google-hosted domains. These guidelines will be effective starting Feb. 1, 2024, and can impact the delivery of emails sent from Zoho Writer. Your organization
                                                • Transitioning from MS Word to Writer: A complete walkthrough

                                                  Hello everyone! We understand moving to a new word processing tool can be difficult, especially if it means switching from a legacy software like MS Word. That's why we've organized an exclusive webinar where we talk you through ways to make your switch from MS Word to Writer as easy as possible. In this webinar, you'll learn: - Why Writer is a simple yet powerful alternative to MS Word. - How to locate your favorite MS Word features and functions in Writer.  - How to migrate your Word documents


                                                Manage your brands on social media



                                                      Zoho TeamInbox Resources

                                                        Zoho DataPrep Resources



                                                          Zoho CRM Plus Resources

                                                            Zoho Books Resources


                                                              Zoho Subscriptions Resources

                                                                Zoho Projects Resources


                                                                  Zoho Sprints Resources


                                                                    Qntrl Resources


                                                                      Zoho Creator Resources



                                                                          Zoho Campaigns Resources


                                                                            Zoho CRM Resources

                                                                            • CRM Community Learning Series

                                                                              CRM Community Learning Series


                                                                            • Kaizen

                                                                              Kaizen

                                                                            • Functions

                                                                              Functions

                                                                            • Meetups

                                                                              Meetups

                                                                            • Kbase

                                                                              Kbase

                                                                            • Resources

                                                                              Resources

                                                                            • Digest

                                                                              Digest

                                                                            • CRM Marketplace

                                                                              CRM Marketplace

                                                                            • MVP Corner

                                                                              MVP Corner





                                                                                Design. Discuss. Deliver.

                                                                                Create visually engaging stories with Zoho Show.

                                                                                Get Started Now