Skip to content

Commit

Permalink
mutiple file to put
Browse files Browse the repository at this point in the history
  • Loading branch information
nj-jay committed Dec 13, 2020
1 parent 110e1b2 commit 12ff58b
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 46 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,21 @@ qn put test.png
# 结果为:
upload successfully
外链为:http://picture.nj-jay.com/test.png

# 你也可以上传多个文件
qn put ~/.pic/maven-compile.png ~/.pic/maven-package.png
# 结果为:
upload successfully
外链为:
http://picture.nj-jay.com/maven-compile.png

upload successfully
外链为:
http://picture.nj-jay.com/maven-package.png

## 如果你要覆盖上传 请使用-w选项
qn put -w test.png
qn put -w test1.png test2.png
```

使用qn -h查看支持的命令
Expand All @@ -104,4 +119,3 @@ upload successfully
- [ ] 支持通配符(批量传入)

- [ ] 改进路径问题(假设传入的路径中使用了`\`或者有空格,在传输之前首先处理这些问题(把路径中的`\`改为/并去除空格)
- [ ] 当七牛中已经存在同名的文件时,提示该信息,并告知使用-w选项可以覆盖该文件
100 changes: 56 additions & 44 deletions cmd/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var (

// putCmd represents the put command
var putCmd = &cobra.Command{
Use: "put <local file> [flags]",
Use: "put <local file> [<local file>] [flags]",
Short: "put file to qiniu server",
Long: `use put command, you can put your local file to qiniu server, and get a url.`,
Run: put,
Expand All @@ -50,28 +50,20 @@ func put(cmd *cobra.Command, params []string){

}

path := params[0]

index := strings.LastIndexAny(path, "/")
accessKey := viper.GetString("ak")

var upload string
secretKey := viper.GetString("sk")

if index != -1 {
bucket := viper.GetString("bucket")

upload = path[index+1:]
if accessKey == "" || secretKey == "" || bucket == "" {

} else {
fmt.Println("请设置ak, sk, bucket")

upload = path
os.Exit(0)

}

accessKey := viper.GetString("ak")

secretKey := viper.GetString("sk")

bucket := viper.GetString("bucket")

mac := qbox.NewMac(accessKey, secretKey)

cfg := storage.Config{
Expand All @@ -80,63 +72,83 @@ func put(cmd *cobra.Command, params []string){

}

var putPolicy storage.PutPolicy
for _, path := range params {

index := strings.LastIndexAny(path, "/")

var upload string

if index != -1 {

upload = path[index+1:]

if overwrite {
} else {

putPolicy = storage.PutPolicy{
upload = path

Scope: fmt.Sprintf("%s:%s", bucket, path),
}

} else {
var putPolicy storage.PutPolicy

putPolicy = storage.PutPolicy{
if overwrite {

putPolicy = storage.PutPolicy{

Scope: fmt.Sprintf("%s:%s", bucket, path),
}

} else {

putPolicy = storage.PutPolicy{

Scope: bucket,
}

Scope: bucket,
}

}
upToken := putPolicy.UploadToken(mac)

bm := storage.NewBucketManager(mac, &cfg)

upToken := putPolicy.UploadToken(mac)
domains, err := bm.ListBucketDomains(bucket)

bm := storage.NewBucketManager(mac, &cfg)
if err != nil {

domains, err := bm.ListBucketDomains(bucket)
fmt.Println("get domain err")

if err != nil {
}

fmt.Println("get domain err")
formUploader := storage.NewFormUploader(&cfg)

}
ret := storage.PutRet{}

formUploader := storage.NewFormUploader(&cfg)
putExtra := storage.PutExtra{

ret := storage.PutRet{}
Params: map[string]string{

putExtra := storage.PutExtra{
"x:name": "picture or some other data",
},
}

Params: map[string]string{

"x:name": "picture or some other data",
},
}
err = formUploader.PutFile(context.Background(), &ret, upToken, upload, path, &putExtra)

if err != nil {

err = formUploader.PutFile(context.Background(), &ret, upToken, upload, path, &putExtra)
fmt.Println("上传失败")

if err != nil {
return
}

fmt.Println("上传失败")
fmt.Println("upload successfully")

return
}
fmt.Println("外链为:")

fmt.Println("upload successfully")
fmt.Println("http://" + domains[0].Domain + "/" + upload)

fmt.Println("外链为:")
fmt.Println()

fmt.Println("http://" + domains[0].Domain + "/" + upload)
}

}

Expand Down
8 changes: 8 additions & 0 deletions docs/nohup.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

(Typora:31206): Gtk-WARNING **: 17:55:41.735: Theme parsing error: gtk.css:6777:29: Missing opening bracket in color definition

(Typora:31206): Gtk-WARNING **: 17:55:41.735: Theme parsing error: gtk.css:6779:34: Missing opening bracket in color definition

(Typora:31206): Gtk-WARNING **: 17:55:41.735: Theme parsing error: gtk.css:6785:28: Missing opening bracket in color definition
(node:31284) Electron: Loading non-context-aware native module in renderer: '/home/jay/SoftWare/Typora-linux-x64/resources/app/node_modules/pathwatcher/build/Release/pathwatcher.node'. This is deprecated, see https://github.com/electron/electron/issues/18397.
(node:31284) Electron: Loading non-context-aware native module in renderer: '/home/jay/SoftWare/Typora-linux-x64/resources/app/node_modules/spellchecker/build/Release/spellchecker.node'. This is deprecated, see https://github.com/electron/electron/issues/18397.
2 changes: 1 addition & 1 deletion docs/typora.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* 上传服务选择Custom Command.并自定义命令为qn put
* 点击验证图片上传选项

<img src="http://picture.nj-jay.com/image-20201213174857642.png" alt="image-20201213174857642" style="zoom:67%;" />
![image-20201213185501418](http://picture.nj-jay.com/image-20201213185501418.png)

## 使用

Expand Down

0 comments on commit 12ff58b

Please sign in to comment.