Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9065587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:32:23+00:00 2026-06-16T16:32:23+00:00

I’m trying to upload a local CSV-file to Google Drive and display it like

  • 0

I’m trying to upload a local CSV-file to Google Drive and display it like a Google Spreadsheet there. However, when I go to my Google Drive and click the link to my file, I can only download it, not view it as a spreadsheet. I’ve tried using the ?convert=true but the file doesn’t get converted. I’ve also tried using application/vnd.google-apps.spreadsheet as the mime type but noting changes or I get a 400 Bad request response.

When I right click the file, I can choose to open with Google Spreadsheets which then displays the file correctly. I can’t find anything about this in the current documentation over at Google and searches on google haven’t help a whole lot.

What I’ve done so far is creating a new, empty Google spreadsheet and tried filling it with my CSV file but that gives me a 500 Internal Error.

        $file = new Google_DriveFile();
        $file->setTitle('Exported data from ' . $this->event->title);
        $file->setDescription('Exported data from ' . $this->event->title);
        $file->setMimeType( 'text/csv' );

        try {
            $createdFile = $this->drive->files->insert($file, array(
              'data' => $data,
              'mimeType' => 'application/vnd.google-apps.spreadsheet'
            ), array('convert'=>true));

            // Uncomment the following line to print the File ID
            // print 'File ID: %s' % $createdFile->getId();

         $additionalParams = array(
    'newRevision' => false,
    'data' => $data,
    'convert'=>true //no change if this is true or false
);
            $newFile = $this->drive->files->get( $createdFile->getId() );
            $newFile->setMimeType('text/csv');
            $updated = $this->drive->files->update($createdFile->getId(), $newFile, $additionalParams);

            preint_r($updated);
        } catch (Exception $e) {
            print "An error occurred: " . $e->getMessage();
        }

I’ve looked at the API for Google Drive but haven’t found anything useful. I’m wondering if I should use the Google Spreadsheets API or is the Google Drive API the one to use solely?

Many thanks in advance,
Waldemar

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T16:32:24+00:00Added an answer on June 16, 2026 at 4:32 pm

    Try the following. It’s from the File:insert reference in the Google documentation but I added the convert parameter:

    /**
     * Insert new file.
     *
     * @param Google_DriveService $service Drive API service instance.
     * @param string $title Title of the file to insert, including the extension.
     * @param string $description Description of the file to insert.
     * @param string $parentId Parent folder's ID.
     * @param string $mimeType MIME type of the file to insert.
     * @param string $filename Filename of the file to insert.
     * @return Google_DriveFile The file that was inserted. NULL is returned if an API error         occurred.
     */
    function insertFile($service, $title, $description, $parentId, $mimeType, $filename) {
      $file = new Google_DriveFile();
      $file->setTitle($title);
      $file->setDescription($description);
      $file->setMimeType($mimeType);
    
      // Set the parent folder.
      if ($parentId != null) {
        $parent = new ParentReference();
        $parent->setId($parentId);
        $file->setParents(array($parent));
      }
    
      try {
        $data = file_get_contents($filename);
    
        $createdFile = $service->files->insert($file, array(
          'data' => $data,
          'mimeType' => $mimeType,
          'convert' => true,
        ));
    
        // Uncomment the following line to print the File ID
        // print 'File ID: %s' % $createdFile->getId();
    
        return $createdFile;
      } catch (Exception $e) {
        print "An error occurred: " . $e->getMessage();
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to render a haml file in a javascript response like so:
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
i want to parse a xhtml file and display in UITableView. what is the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.