prasmussen / gdrive

Google Drive CLI Client
MIT License
8.99k stars 1.19k forks source link

Converting CSV file to Google Spreadsheet through gdrive api not working #303

Open karunasaxena opened 7 years ago

karunasaxena commented 7 years ago

I have tried following commands to make csv file open as a spreadsheet while I am uploading through gdrive tool but always it is uploading as a google doc or ms-excel. But for either of the case I have to select the option "Open With" -> Google Spreadsheet which is creating one extra file of same name.

sample.csv 1,2,3,4

gdrive upload sample.csv gdrive upload --mime 'text/csv' sample.csv gdrive import sample.csv gdrive upload --mime 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' sample.csv

Can anyone please help me on this?

shellac commented 7 years ago

I think the command ought to be:

gdrive import --mime 'text/csv' sample.csv # Edit - sorry, import not upload

Imported [ID] with mime type: 'application/vnd.google-apps.spreadsheet'

However that isn't working for me - I get a text document. I wonder whether it ought to be using application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, which has worked for me using the API directly.

demidovakatya commented 7 years ago

Same problem here.

shellac commented 7 years ago

For anyone else having issues with this here is (sort of) a work around.

However it's far from perfect (I'm using a service account, for example).

This python code works, so I suspect gdrive is at fault:

from oauth2client.service_account import ServiceAccountCredentials
from googleapiclient.discovery import build
from googleapiclient.http import MediaFileUpload
import httplib2

scopes = ['https://www.googleapis.com/auth/drive']

credentials = ServiceAccountCredentials.from_json_keyfile_name(
    'etc/credentials.json', scopes)

http = httplib2.Http()
http = credentials.authorize(http)

drive_service = build("drive", "v3", http=http)

file_metadata = {
  'name' : 'Test Sheet',
  'mimeType' : 'application/vnd.google-apps.spreadsheet',
  'parents' : []
}

media = MediaFileUpload('test.csv',
                    mimetype='text/csv',
                    resumable=True)

file = drive_service.files().create(body=file_metadata,
                                media_body=media,
                                fields='id').execute()
karunasaxena commented 7 years ago

Thanks. It might be a good temporary solution if it works.

For time being, this methodology can be referred either by using gdrive or by using any other free extension say "Sheetgo"

lucasclopesr commented 4 years ago

Since this is still open, might as well tell you what has worked for me:

gdrive upload --mime text/csv sample.csv

Hope it helps for the future.

AnselmC commented 3 years ago

Is there any way to get this to work for gdrive sync upload? I'm uploading data in bulk - only filetype is csv but there's also an underlying directory structure.