Parcourir la source

download attachment and save as a new name

master
Patrick Peng Sun il y a 8 ans
Parent
révision
a65814671a
2 fichiers modifiés avec 11 ajouts et 3 suppressions
  1. +10
    -3
      crmAttachment.go
  2. +1
    -0
      crmAttachment_test.go

+ 10
- 3
crmAttachment.go Voir le fichier

"fmt" "fmt"
"io/ioutil" "io/ioutil"
"log" "log"
"os"
) )


type crmFileInfo struct { type crmFileInfo struct {
} }


func crmDownloadAttachmentAs(fileID, saveAs string) (err error) { func crmDownloadAttachmentAs(fileID, saveAs string) (err error) {
return nil

f, err := crmDownloadAttachment(fileID)
if err != nil {
return
}
err = os.Rename(f, saveAs)
return
} }


func crmDownloadAttachment(fileID string) (err error) {
func crmDownloadAttachment(fileID string) (filename string, err error) {
u := crmURL4DownloadAttachmet(fileID) u := crmURL4DownloadAttachmet(fileID)
headers := map[string]string{} headers := map[string]string{}
headers["Authorization"] = crmAuthHeader() headers["Authorization"] = crmAuthHeader()
f, _, err := saveURLwithHTTPHeader(u, headers) f, _, err := saveURLwithHTTPHeader(u, headers)
log.Println(f) log.Println(f)
return nil
return f, err
} }


func crmURL4DownloadAttachmet(fileID string) string { func crmURL4DownloadAttachmet(fileID string) string {

+ 1
- 0
crmAttachment_test.go Voir le fichier

func TestCRMDownloadAttachment(t *testing.T) { func TestCRMDownloadAttachment(t *testing.T) {
SetupConfig() SetupConfig()
crmDownloadAttachment("591ef9c61d6ca779c") crmDownloadAttachment("591ef9c61d6ca779c")
crmDownloadAttachmentAs("591ef9c61d6ca779c", "/tmp/wechat_hitxy_测试")
} }

Chargement…
Annuler
Enregistrer