I am using following code to download googledrive documents
to list files:
*listArgs := listAllFilesArgs{ query: "", fields:
[]googleapi.Field{"nextPageToken",
"files(id,name,mimeType,size,md5Checksum,parents,trashed,modifiedTime,starred)"},
} files,
err := self.listAllFiles(listArgs)*
to download documents:
*res**,* *err* *:=* *self**.**service**.**Files**.**Get**(**f**.**Id**).*
*Context**(**ctx**).**Download**()*
*if* *err* *!=* *nil* *{*
*if* *isTimeoutError**(**err**)* *{*
*return* *0**,* *0**,* *fmt**.**Errorf**(**"Failed*
*to* *download* *file:* *timeout,* *no* *data* *was* *transferred* *for*
*%s"**,* *args**.**Timeout**)*
*}*
*return* *0**,* *0**,* *fmt**.**Errorf**(**"Failed* *to*
*download* *file:* *%s"**,* *err**)*
*}*
*//* *Close* *body* *on* *function* *exit*
*defer* *res**.**Body**.**Close**()*
*//* *Path* *to* *file*
*filename* *:=* *strings**.**Replace**(**f**.**Name**,* *"*
*"**,* *"_"**,* *-**1**)*
*fpath* *:=*
*sbgoclient**.**GetLocalFilename_binary**(**filename**,* *sbConfig**,*
*extension**)*
*fmt**.**Println**(**fpath**)*
*if* *_**,* *err* *:=* *os**.**Stat**(**fpath**);*
*os**.**IsNotExist**(**err**)* *{*
*out**,* *err* *:=* *os**.**Create**(**fpath**)*
*if* *err* *!=* *nil* *{*
*return* *0**,* *0**,* *fmt**.**Errorf**(**"Failed*
*to* *create* *file* *%s:* *%s"**,* *filename**,* *err**)*
*}*
*n**,* *err* *:=* *io**.**Copy**(**out**,* *res**.**Body**)*
*if* *err* *!=* *nil* *{*
*return* *0**,* *0**,* *fmt**.**Errorf**(**"Error*
*while* *downloading* *%s* *-* *%s"**,* *f**.**Id**,* *err**)*
*}*
*fmt**.**Println**(**n**,* *"bytes* *downloaded."**)*
*fmt**.**Println**(**"response* *is"**,* *res**.**Body**)*
*info**,* *_* *:=* *os**.**Stat**(**fpath**)*
*fmt**.**Println**(**"***************************************"**,*
*info**.**ModTime**())*
*this works fine for me but after downmload around 6000 documents it becomes
sooper slow and I have enough space in my system.*
*Please refer my code above and let me if there are any corrections.*
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.