Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

No conversion on import for cvs #154

Open
anguianoa opened this issue Jun 7, 2016 · 23 comments
Open

No conversion on import for cvs #154

anguianoa opened this issue Jun 7, 2016 · 23 comments

Comments

@anguianoa
Copy link

When I do

./gdrive import myfile.cvs

it is not converting to a spreadsheet. It imports it as a doc

version 2.1.0 running on ubuntu 14.

By the way great tool!

@anguianoa
Copy link
Author

It looks like it is this line

drive/upload.go
184 f, err := self.service.Files.Create(dstFile).Fields("id", "name", "size", "md5Checksum", "webContentLink").Context(ctx).Media(reader, chunkSize).Do()

Seem like it should have a Convert flag somewhere. I was not able to trace the google api that it used to do in the api 2.0

@anguianoa
Copy link
Author

Ok, looking further. It looks like v3 is using the mime type to determine if it should convert.

When i import my file it looks like it has the right mime type.

It is still not converting to a spreadsheet. It is still a doc.

Imported 1qKpH0y4NdNiFms9huEdeXurhOIHSDtSc7LuXQE3gvXU with mime type: 'application/vnd.google-apps.spreadsheet'

@PaulCapestany
Copy link

I'm having the same issue trying to upload .csv files.

@ehno5
Copy link

ehno5 commented Jun 20, 2016

same problem 👎

@hemsh
Copy link

hemsh commented Jun 21, 2016

I am having same problem

@anguianoa
Copy link
Author

I'm beginning to think that this is a google api problem and looked at the code

I tried the other call to upload

gdrive upload --mime "text/tab-separated-values" myfile.csv

it uploaded with, but the file icon was a green box with an X in it.

It didn't convert it, but it did let me convert it after i opened it. The importing command from above would make it to a google doc and it would not let me convert it on the google drive.

@PaulCapestany
Copy link

Hey @prasmussen, just wanted to ping you directly about this conversion issue in case you might know of an obvious reason for why things are seemingly currently broken?

If not, I'd be happy to dive into the code to try to sort things out myself (and submit a pull request, if you're still cool with accepting those)—just hadn't been annoyed by this issue enough to do so myself yet =P

Would be great to hear from you either way!

p.s. thanks for having made such an awesome open source CLI gdrive tool 👍

@yurtesen
Copy link

I am having the same issue. It says imported with mime type spreadsheet, but drive opens it in text editor.

@Simonzhaohui
Copy link

I got same issue. Do you plan to fix that ? @prasmussen

@PaulCapestany
Copy link

I've got a (somewhat lame + gross, but effective) hacky fix that's been working quite well with regard to importing docs (including csvs/tsvs) into gdrive-native formats with no muss and no fuss.

If it's the case that the owner of this repo is too busy with other things to bother with issues and/or PRs, feel free to @ mention me here if you'd be interested in the fix. If there's enough interest (and prasmussen remains MIA) I'd be happy to publicize my fork (don't wanna just do that and then seem like I'm competing with this original repo though—if at all avoidable... 😬)

@PaulCapestany
Copy link

p.s. @prasmussen my "fix" is really a regression (to an earlier version of the gDrive API)—also, I'm not totally sure how to incorporate it into a PR for the current version of gDrive API... which is why I haven't officially opened a PR for this. Totally open to discussing it here though if you're up for it!

@yurtesen
Copy link

yurtesen commented Aug 11, 2016

I only needed to upload files and convert so I wrote a small program which does exactly that, it also can detect existing file with same name and overwrite it. It uses pydrive and very small (31 lines only!)

Only takes 2 arguments, parent directory ID value and file path. (you can get the ID value by entering to folder and copying from URL. It is usually some long text like 0B5XXXXY9KddXXXXXXXA2c3ZXXXX. Script was running for a month now daily and it did not ask for re-auth etc. So -> Works For Me TM! <- You may need to update some paths and what not...

So I use it like:
upload.py 0B5XXXXY9KddXXXXXXXA2c3ZXXXX /path/to/my/file

I only tested it with .tsv files and it converts successfully to google sheets file so when I click on it, I get sheets...

#!/usr/bin/python

import sys
import base64
from os import path
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from pydrive.settings import LoadSettingsFile

gauth = GoogleAuth()
gauth.settings = LoadSettingsFile(filename='/usr/local/scripts/gdrive/settings.yaml')
gauth.CommandLineAuth()

drive = GoogleDrive(gauth)
parentId = sys.argv[1]
myFilePath = sys.argv[2]
myFileName = path.basename(sys.argv[2])


file_list = drive.ListFile({'q': '"'+parentId+'" in parents and title="'+myFileName+'" and trashed=false'}).GetList()

# If file is found, update it, otherwise create new file
if len(file_list) == 1:
    myFile = file_list[0]
else:
    myFile = drive.CreateFile({"parents": [{"kind": "drive#fileLink", "id": parentId}]})


myFile.SetContentFile(myFilePath)
myFile['title'] = myFileName
myFile.Upload({'convert': True})

settings.yaml

client_config_backend: settings
client_config:
  client_id: INSERT YOUR CLIENT_ID HERE
  client_secret: INSERT YOUR SECRET HERE
  auth_uri: https://accounts.google.com/o/oauth2/auth
  token_uri: https://accounts.google.com/o/oauth2/token
  redirect_uri: urn:ietf:wg:oauth:2.0:oob
  revoke_uri:

save_credentials: True
save_credentials_backend: file
save_credentials_file: /usr/local/scripts/gdrive/credentials.json

get_refresh_token: True

oauth_scope:
  - https://www.googleapis.com/auth/drive.file

@RNabel
Copy link

RNabel commented Oct 25, 2016

@yurtesen I am the maintainer of PyDrive - would you mind me adding this script to the examples published in the repository?

@yurtesen
Copy link

@RNabel thanks for asking. I am surprised that you even found it here :) I don't mind at all. It probably would be worthwhile to convert setting file path to a variable in the script. This was a real quick hack so I didn't bother making it pretty.

I would appreciate it if you could just add a line showing that it came from me :) Perhaps something like, if it is ok for you.

 # Evren Yurtesen - https://github.com/yurtesen/

tomofumi-nakano added a commit to tomofumi-nakano/gdrive that referenced this issue Nov 10, 2016
@RNabel
Copy link

RNabel commented Nov 17, 2016

@yurtesen Just pushed your sample to PyDrive's dev branch, feel free to comment on the commit!
(My apologies for discussing this in this thread)

@anneschuth
Copy link

This seems to be an issue still. The response mentions the right MIME-type ('application/vnd.google-apps.spreadsheet') but the document isn't converted into a spreadsheet.

@tomofumi-nakano
Copy link

Someone, can you see my patch? 4540c5c
The patch solves this issue in my environment.

I guess a lack option of ContentType might cause the issue.
All sample codes set mimeType in the page https://developers.google.com/drive/v3/web/integrate-open#open_and_convert_google_docs_in_your_app

@carrodher
Copy link

carrodher commented Feb 23, 2017

Hi @tomofumi-nakano, I am trying your solution (PR #224), but it doesn't work for me, it is possible that I am doing something wrong. I want to upload a local .csv as a Google Sheet.
My steps are:

go get github.com/tomofumi-nakano/gdrive
cd /go/bin/gdrive
./gdrive import --parent 0B_ulNgvK6XduaUcz3UaaeGRSdWc4 /tmp/nami20170222.csv

I hope the result is a Google Sheet like this:
screen shot 2017-02-23 at 09 38 25

But I obtain:
screen shot 2017-02-23 at 09 39 08

Am I doing something wrong? Thanks!

@tomofumi-nakano
Copy link

@carrodher

Sorry, I forgot about a command option.
--mime is required.

i.e.

./gdrive import --parent 0B_ulNgvK6XduaUcz3UaaeGRSdWc4 --mime text/csv /tmp/nami20170222.csv

@carrodher
Copy link

Thanks for your answer @tomofumi-nakano, but I continue with the same issue using --mime text/csv option...

@SapelliBR
Copy link

same issue... the file is imported like a doc.

tomofumi-nakano added a commit to tomofumi-nakano/gdrive that referenced this issue May 12, 2017
@tomofumi-nakano
Copy link

@carrodher
Finally I found the cause.

This program use local packages and use github.com/username/...
i.e.
https://github.com/prasmussen/gdrive/blob/master/handlers_drive.go#L14

	"github.com/prasmussen/gdrive/drive"

It mean this program imports and use the original repository (prasmussen's) code, even if we modify local code.

That is why.

We need change the import source package name if we use forked repositories.
For validation, I put the fix code at latest commit in my forked repository.
Please try again.

@svsundar
Copy link

svsundar commented May 17, 2017

Hi Tomofumi-nakano, carrodher,

I have the same requirement and I need to copy the CSV to google drive as a google spreadsheet.

I am following the same steps
go get github.com/tomofumi-nakano/gdrive
cd /go/bin/gdrive
./gdrive import --parent ****driveID /tmp/test.csv

I hope this will access your forked code branch and downloaded the code.

and I am getting the below error,

Failed to upload file: googleapi: Error 400: Bad Request, badRequest

I thought it could be authentication and I tried grdive list and its working perfect. Upload is also working.

Any idea? Could you please help? Thanks a bunch in advance.

Regards
Vaiyravan

msfjarvis pushed a commit to msfjarvis/gdrive that referenced this issue Nov 12, 2018
[harsh: Fix formatting]
Signed-off-by: Harsh Shandilya <msfjarvis@gmail.com>
msfjarvis pushed a commit to msfjarvis/gdrive that referenced this issue Feb 21, 2021
[harsh: Fix formatting]
Signed-off-by: Harsh Shandilya <msfjarvis@gmail.com>
msfjarvis pushed a commit to msfjarvis/gdrive that referenced this issue Feb 21, 2021
[harsh: Fix formatting]
Signed-off-by: Harsh Shandilya <msfjarvis@gmail.com>
msfjarvis pushed a commit to msfjarvis/gdrive that referenced this issue Mar 8, 2021
[harsh: Fix formatting]
Signed-off-by: Harsh Shandilya <msfjarvis@gmail.com>
msfjarvis pushed a commit to msfjarvis/gdrive that referenced this issue Apr 4, 2022
[harsh: Fix formatting]
Signed-off-by: Harsh Shandilya <msfjarvis@gmail.com>
DroidFreak32 pushed a commit to DroidFreak32/gdrive_cli that referenced this issue Aug 2, 2022
[harsh: Fix formatting]
Signed-off-by: Harsh Shandilya <msfjarvis@gmail.com>
DroidFreak32 pushed a commit to DroidFreak32/gdrive_cli that referenced this issue Aug 2, 2022
[harsh: Fix formatting]
Signed-off-by: Harsh Shandilya <msfjarvis@gmail.com>
Signed-off-by: DroidFreak32 <rushabshah32@gmail.com>
growtopiajaw pushed a commit to growtopiajaw/gdrive that referenced this issue Nov 25, 2022
[harsh: Fix formatting]
Signed-off-by: Harsh Shandilya <msfjarvis@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests