Skip to content
Merged
2 changes: 1 addition & 1 deletion cmd/asyncfetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strconv"
"time"

"github.com/qiniu/api.v7/v7/storage"
"github.com/qiniu/go-sdk/v7/storage"
"github.com/qiniu/qshell/v2/iqshell"
"github.com/spf13/cobra"
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/cdn.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"time"

"github.com/astaxie/beego/logs"
"github.com/qiniu/api.v7/v7/cdn"
"github.com/qiniu/go-sdk/v7/cdn"
"github.com/qiniu/qshell/v2/iqshell"
"github.com/spf13/cobra"
)
Expand Down
38 changes: 28 additions & 10 deletions cmd/putfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"
"time"

"github.com/qiniu/api.v7/v7/storage"
"github.com/qiniu/go-sdk/v7/storage"
"github.com/qiniu/qshell/v2/iqshell"
"github.com/spf13/cobra"
)
Expand All @@ -19,6 +19,7 @@ var upSettings = storage.Settings{
}

var (
isResumeV2 bool
pOverwrite bool
mimeType string
fileType int
Expand Down Expand Up @@ -52,6 +53,7 @@ func init() {
formPutCmd.Flags().StringVarP(&callbackUrls, "callback-urls", "l", "", "upload callback urls, separated by comma")
formPutCmd.Flags().StringVarP(&callbackHost, "callback-host", "T", "", "upload callback host")

RePutCmd.Flags().BoolVarP(&isResumeV2, "v2", "", false, "use resumable upload v2 APIs to upload")
RePutCmd.Flags().BoolVarP(&pOverwrite, "overwrite", "w", false, "overwrite mode")
RePutCmd.Flags().StringVarP(&mimeType, "mimetype", "t", "", "file mime type")
RePutCmd.Flags().IntVarP(&fileType, "storage", "s", 0, "storage type")
Expand Down Expand Up @@ -224,20 +226,13 @@ func ResumablePut(cmd *cobra.Command, params []string) {
policy.CallbackBodyType = "application/x-www-form-urlencoded"
}

var putExtra storage.RputExtra
var upHost string

if rupHost == "" {
upHost = iqshell.UpHost()
} else {
upHost = rupHost
}
putExtra = storage.RputExtra{
UpHost: upHost,
}
if mimeType != "" {
putExtra.MimeType = mimeType
}

mac, err := iqshell.GetMac()
if err != nil {
Expand All @@ -252,8 +247,31 @@ func ResumablePut(cmd *cobra.Command, params []string) {

fmt.Printf("Uploading %s => %s : %s ...\n", localFile, bucket, key)

resume_uploader := storage.NewResumeUploader(nil)
err = resume_uploader.PutFile(context.Background(), &putRet, uptoken, key, localFile, &putExtra)
if isResumeV2 {

resume_uploader := storage.NewResumeUploaderV2(nil)

putExtra := storage.RputV2Extra{
UpHost: upHost,
}
if mimeType != "" {
putExtra.MimeType = mimeType
}

err = resume_uploader.PutFile(context.Background(), &putRet, uptoken, key, localFile, &putExtra)
} else {

resume_uploader := storage.NewResumeUploader(nil)

putExtra := storage.RputExtra{
UpHost: upHost,
}
if mimeType != "" {
putExtra.MimeType = mimeType
}

err = resume_uploader.PutFile(context.Background(), &putRet, uptoken, key, localFile, &putExtra)
}

fmt.Println()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/qupload.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"

"github.com/astaxie/beego/logs"
"github.com/qiniu/api.v7/v7/storage"
"github.com/qiniu/go-sdk/v7/storage"
"github.com/qiniu/qshell/v2/iqshell"
"github.com/spf13/cobra"
)
Expand Down
3 changes: 2 additions & 1 deletion cmd/qupload2.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strings"

"github.com/astaxie/beego/logs"
"github.com/qiniu/api.v7/v7/storage"
"github.com/qiniu/go-sdk/v7/storage"
"github.com/qiniu/qshell/v2/iqshell"
"github.com/spf13/cobra"
)
Expand All @@ -25,6 +25,7 @@ var (

func init() {
qUpload2Cmd.Flags().Int64Var(&up2threadCount, "thread-count", 0, "multiple thread count")
qUpload2Cmd.Flags().BoolVarP(&uploadConfig.ResumableAPIV2, "resumable-api-v2", "", false, "use resumable upload v2 APIs to upload")
qUpload2Cmd.Flags().StringVar(&uploadConfig.SrcDir, "src-dir", "", "src dir to upload")
qUpload2Cmd.Flags().StringVar(&uploadConfig.FileList, "file-list", "", "file list to upload")
qUpload2Cmd.Flags().StringVar(&uploadConfig.Bucket, "bucket", "", "bucket")
Expand Down
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (

"github.com/astaxie/beego/logs"
homedir "github.com/mitchellh/go-homedir"
"github.com/qiniu/api.v7/v7/client"
"github.com/qiniu/api.v7/v7/storage"
"github.com/qiniu/go-sdk/v7/client"
"github.com/qiniu/go-sdk/v7/storage"
"github.com/qiniu/qshell/v2/iqshell"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down
2 changes: 1 addition & 1 deletion cmd/rs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"
"time"

"github.com/qiniu/api.v7/v7/storage"
"github.com/qiniu/go-sdk/v7/storage"
"github.com/qiniu/qshell/v2/iqshell"
"github.com/spf13/cobra"
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/rsbatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"sync"
"time"

"github.com/qiniu/api.v7/v7/storage"
"github.com/qiniu/go-sdk/v7/storage"
"github.com/qiniu/qshell/v2/iqshell"
"github.com/spf13/cobra"
)
Expand Down
3 changes: 2 additions & 1 deletion cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var (
)

func init() {
syncCmd.Flags().BoolVarP(&isResumeV2, "resumable-api-v2", "", false, "use resumable upload v2 APIs to upload")
syncCmd.Flags().StringVarP(&upHostIp, "uphost", "u", "", "upload host")
syncCmd.Flags().StringVarP(&saveKey, "key", "k", "", "save as <key> in bucket")
RootCmd.AddCommand(syncCmd)
Expand Down Expand Up @@ -50,7 +51,7 @@ func Sync(cmd *cobra.Command, params []string) {
bm := iqshell.GetBucketManager()
//sync
tStart := time.Now()
syncRet, sErr := bm.Sync(srcResUrl, bucket, key, upHostIp)
syncRet, sErr := bm.Sync(srcResUrl, bucket, key, upHostIp, isResumeV2)
if sErr != nil {
logs.Error(sErr)
os.Exit(iqshell.STATUS_ERROR)
Expand Down
6 changes: 3 additions & 3 deletions cmd/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"os"
"strings"

"github.com/qiniu/api.v7/v7/auth/qbox"
"github.com/qiniu/api.v7/v7/conf"
"github.com/qiniu/api.v7/v7/storage"
"github.com/qiniu/go-sdk/v7/auth/qbox"
"github.com/qiniu/go-sdk/v7/conf"
"github.com/qiniu/go-sdk/v7/storage"
"github.com/qiniu/qshell/v2/iqshell"
"github.com/spf13/cobra"
)
Expand Down
4 changes: 3 additions & 1 deletion docs/qupload.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ ThreadCount ==> 并发上传的协程数量,默认为1,即文件一个个上
"log_level" : "info",
"log_rotate" : 1,
"log_stdout" : false,
"file_type" : 0
"file_type" : 0,
"resumable-api-v2" : false
}
```

Expand Down Expand Up @@ -95,6 +96,7 @@ ThreadCount ==> 并发上传的协程数量,默认为1,即文件一个个上
|log_stdout|上传日志是否同时输出一份到标准终端,默认为false,主要在调试上传功能时可以指定为true|Y|
|file_type|文件存储类型,默认为`0`(标准存储) `1`为低频存储|Y|
|delete_on_success|上传成功的文件,同时删除本地文件,以达到节约磁盘的目的,比如日志归档的场景,默认为`false`,如果需要开启功能,设置为`true`即可。|Y|
|resumable-api-v2|使用分片 V2 进行上传,默认为`false`使用分片 V1 |Y|

对于那么多的参数,我们可以分为几类来解释:

Expand Down
1 change: 1 addition & 0 deletions docs/qupload2.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ Flags:
--success-list string upload success file list
--thread-count int multiple thread count
--up-host string upload host
--resumable-api-v2 use resumable upload v2 APIs to upload
```
19 changes: 12 additions & 7 deletions docs/rput.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@
`rput`命令使用七牛支持的分片上传的方式来上传一个文件,一般文件大小较大的情况下,可以使用分片上传来有效地保证文件上传的成功。

参考文档:

[创建块 (mkblk)](http://developer.qiniu.com/code/v6/api/kodo-api/up/mkblk.html)

[上传片 (bput)](http://developer.qiniu.com/code/v6/api/kodo-api/up/bput.html)

[创建文件 (mkfile)](http://developer.qiniu.com/code/v6/api/kodo-api/up/mkfile.html)
[分片上传 V1](https://developer.qiniu.com/kodo/7443/shard-to-upload)
[分片上传 V2](https://developer.qiniu.com/kodo/6364/multipartupload-interface)

# 格式

```
qshell rput [--overwrite] [--mimetype <MimeType>] [--callback-urls <CallbackUrls>] [--callback-host <CallbackHost>] [--storage <StorageType> ] <Bucket> <Key> <LocalFile>
qshell rput [--overwrite] [--v2] [--mimetype <MimeType>] [--callback-urls <CallbackUrls>] [--callback-host <CallbackHost>] [--storage <StorageType> ] <Bucket> <Key> <LocalFile>
```

其中 `Overwrite`,`MimeType`,`StorageType` (0 -> 标准存储, 1 - 低频存储)参数可根据需要指定一个或者多个,参数顺序随意,程序会自动识别。
Expand All @@ -34,16 +30,25 @@ qshell rput [--overwrite] [--mimetype <MimeType>] [--callback-urls <CallbackUrls
| StorageType | 文件存储类型,默认为`0`(标准存储) `1`为低频存储 | Y |
| CallbackUrls | 上传回调地址,可以指定多个地址, 以逗号分开 | Y |
| CallbackHost | 上传回调HOST, 必须和CallbackUrls一起指定 | Y |
| v2 | 使用分片上传 API V2 进行上传,默认为`false`, 使用 V1 上传 | Y |


# 示例

1.上传本地文件`/Users/jemy/Documents/qiniu.mp4`到空间`if-pbl`里面。

使用使用分片上传 API V1

```
$ qshell rput if-pbl qiniu.mp4 /Users/jemy/Documents/qiniu.mp4
```

使用使用分片上传 API V2

```
$ qshell rput if-pbl qiniu.mp4 /Users/jemy/Documents/qiniu.mp4 --v2
```

输出:

```
Expand Down
5 changes: 3 additions & 2 deletions docs/sync.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ qshell sync <SrcResUrl> <Bucket> <Key> [<UpHostIp>]
|Bucket|空间名称,可以为公开空间或者私有空间|N|
|Key|该资源保存在空间中的名字|N|
|UpHostIp|上传入口的IP地址,一般在大文件的情况下,可以指定上传入口的IP来减少DNS环节,提升同步速度|Y|
|resumable-api-v2|使用分片 v2 进行上传,默认使用 v1|Y|


**备注:**
Expand All @@ -46,9 +47,9 @@ $ dig up-na0.qiniu.com

# 示例

抓取一个资源并以指定的文件名保存在七牛的空间里面:
使用分片 v2 抓取一个资源并以指定的文件名保存在七牛的空间里面:

```
$ qshell sync http://if-pbl.qiniudn.com/test_big_movie.mp4 if-pbl test.mp4
$ qshell sync http://if-pbl.qiniudn.com/test_big_movie.mp4 if-pbl test.mp4 --resumable-api-v2

```
35 changes: 21 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
module github.com/qiniu/qshell/v2

require (
github.com/aliyun/aliyun-oss-go-sdk v2.1.2+incompatible
github.com/astaxie/beego v1.12.2
github.com/aws/aws-sdk-go v1.33.0
github.com/aliyun/aliyun-oss-go-sdk v2.1.6+incompatible
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6 // indirect
github.com/astaxie/beego v1.12.3
github.com/aws/aws-sdk-go v1.37.31
github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/golang/snappy v0.0.1 // indirect
github.com/golang/snappy v0.0.3 // indirect
github.com/magiconair/properties v1.8.4 // indirect
github.com/mitchellh/go-homedir v1.1.0
github.com/mitchellh/mapstructure v1.3.2 // indirect
github.com/pelletier/go-toml v1.8.0 // indirect
github.com/qiniu/api.v7/v7 v7.5.0
github.com/mitchellh/mapstructure v1.4.1 // indirect
github.com/pelletier/go-toml v1.8.1 // indirect
github.com/qiniu/go-sdk/v7 v7.9.2
github.com/satori/go.uuid v1.2.0 // indirect
github.com/spf13/afero v1.3.1 // indirect
github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18 // indirect
github.com/spf13/afero v1.5.1 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/spf13/cobra v1.0.0
github.com/spf13/cobra v1.1.3
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.7.0
github.com/spf13/viper v1.7.1
github.com/stretchr/testify v1.6.1
github.com/syndtr/goleveldb v1.0.0
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae // indirect
golang.org/x/text v0.3.3
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e // indirect
gopkg.in/ini.v1 v1.57.0 // indirect
github.com/ugorji/go v1.1.4 // indirect
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005 // indirect
golang.org/x/text v0.3.5
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba // indirect
golang.org/x/tools v0.0.0-20200117065230-39095c1d176c // indirect
gopkg.in/ini.v1 v1.62.0 // indirect
)

go 1.13
Loading