Skip to content

Commit

Permalink
solved #16
Browse files Browse the repository at this point in the history
  • Loading branch information
gaowanliang committed Apr 13, 2021
1 parent 5152861 commit 34a58b4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
13 changes: 7 additions & 6 deletions src/googledrive/gdUpload.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func GetAllFile(pathname string, folderIDList []string, srv *drive.Service, star
return err
}
_, foldName := filepath.Split(pathname)
log.Println(foldName)
//log.Println(foldName)
var createFolder *drive.File
if folderIDList == nil {
createFolder, err = srv.Files.Create(&drive.File{Name: foldName, MimeType: "application/vnd.google-apps.folder"}).Do()
Expand Down Expand Up @@ -151,7 +151,7 @@ func GetAllFile(pathname string, folderIDList []string, srv *drive.Service, star
log.Fatalf("error opening %q: %v", fullName, err)
}
defer f.Close()
log.Println("file", fi.Name(), fullName)
//log.Println("file", fi.Name(), fullName)
//上傳檔案,create要給定檔案名稱,要傳進資料夾就加上Parents參數給定folderID的array,media傳入我們要上傳的檔案,最後Do
_, err = srv.Files.Create(&drive.File{Name: fi.Name(), Parents: tempFolderIDList}).Media(f).Do()
if err != nil {
Expand Down Expand Up @@ -216,6 +216,10 @@ func CreateNewInfo(code string) string {
}

func Upload(infoPath string, filePath string, sendMsg func() func(text string), locText func(text string) string) {
ctx, config := gdInit()
tok, _ := tokenFromFile(infoPath)
client := config.Client(ctx, tok)
srv, err := drive.New(client)
username := strings.ReplaceAll(filepath.Base(infoPath), ".json", "")
// restoreOption := "orig"
oldDir, err := os.Getwd()
Expand All @@ -229,10 +233,7 @@ func Upload(infoPath string, filePath string, sendMsg func() func(text string),
filePath = path.Base(filePath)
temp := sendMsg()
temp("`" + filePath + "`" + locText("startUploadGoogleDrive"))
ctx, config := gdInit()
tok, _ := tokenFromFile(infoPath)
client := config.Client(ctx, tok)
srv, err := drive.New(client)

if err != nil {
log.Fatalf("Unable to retrieve drive Client %v", err)

Expand Down
13 changes: 7 additions & 6 deletions vendor/googledrive/gdUpload.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func GetAllFile(pathname string, folderIDList []string, srv *drive.Service, star
return err
}
_, foldName := filepath.Split(pathname)
log.Println(foldName)
//log.Println(foldName)
var createFolder *drive.File
if folderIDList == nil {
createFolder, err = srv.Files.Create(&drive.File{Name: foldName, MimeType: "application/vnd.google-apps.folder"}).Do()
Expand Down Expand Up @@ -151,7 +151,7 @@ func GetAllFile(pathname string, folderIDList []string, srv *drive.Service, star
log.Fatalf("error opening %q: %v", fullName, err)
}
defer f.Close()
log.Println("file", fi.Name(), fullName)
//log.Println("file", fi.Name(), fullName)
//上傳檔案,create要給定檔案名稱,要傳進資料夾就加上Parents參數給定folderID的array,media傳入我們要上傳的檔案,最後Do
_, err = srv.Files.Create(&drive.File{Name: fi.Name(), Parents: tempFolderIDList}).Media(f).Do()
if err != nil {
Expand Down Expand Up @@ -216,6 +216,10 @@ func CreateNewInfo(code string) string {
}

func Upload(infoPath string, filePath string, sendMsg func() func(text string), locText func(text string) string) {
ctx, config := gdInit()
tok, _ := tokenFromFile(infoPath)
client := config.Client(ctx, tok)
srv, err := drive.New(client)
username := strings.ReplaceAll(filepath.Base(infoPath), ".json", "")
// restoreOption := "orig"
oldDir, err := os.Getwd()
Expand All @@ -229,10 +233,7 @@ func Upload(infoPath string, filePath string, sendMsg func() func(text string),
filePath = path.Base(filePath)
temp := sendMsg()
temp("`" + filePath + "`" + locText("startUploadGoogleDrive"))
ctx, config := gdInit()
tok, _ := tokenFromFile(infoPath)
client := config.Client(ctx, tok)
srv, err := drive.New(client)

if err != nil {
log.Fatalf("Unable to retrieve drive Client %v", err)

Expand Down

0 comments on commit 34a58b4

Please sign in to comment.