Skip to content

Commit f4f0704

Browse files
authored
Merge pull request #3 from kuixiao/from_xk
check gosdk demo code
2 parents cc42de5 + b75b307 commit f4f0704

20 files changed

+217
-156
lines changed

collections/_go-sdk/上传回调.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ SDK 提供了文件上传后进行回调(Callback)的功能。您只需要
1919
| AsyncUploadWithPolicy | 异步分片并发上传回调,完整代码详见 [Github](https://github.com/ufilesdk-dev/ufile-gosdk/blob/master/file_mutipart_upload_with_policy.go)|
2020

2121
> 说明
22+
>
2223
> * 以上所有分片上传回调实际上都是通过调用 FinishMultipartUploadWithPolicy 完成。
2324
2425

collections/_go-sdk/分片上传.md

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ import (
3535
)
3636

3737
const (
38-
ConfigFile = ""
39-
FilePath = ""
40-
KeyName = ""
38+
ConfigFile = "config.json"
39+
FilePath = "FakeBigFile.txt"
40+
KeyName = "FakeBigFile.txt"
4141
MimeType = ""
4242
)
4343

@@ -78,9 +78,9 @@ import (
7878
)
7979

8080
const (
81-
ConfigFile = ""
82-
FilePath = ""
83-
KeyName = ""
81+
ConfigFile = "config.json"
82+
FilePath = "FakeBigFile.txt"
83+
KeyName = "FakeBigFile.txt"
8484
MimeType = ""
8585
)
8686

@@ -97,7 +97,7 @@ func main() {
9797
}
9898

9999
// 异步分片上传本地文件
100-
err = req.AsycMPut(FilePath, KeyName, MimeType)
100+
err = req.AsyncMPut(FilePath, KeyName, MimeType)
101101
if err != nil {
102102
log.Fatalf("%s\n", err.Error())
103103
}
@@ -121,9 +121,9 @@ import (
121121
)
122122

123123
const (
124-
ConfigFile = ""
125-
FilePath = ""
126-
KeyName = ""
124+
ConfigFile = "config.json"
125+
FilePath = "FakeBigFile.txt"
126+
KeyName = "FakeBigFile.txt"
127127
MimeType = ""
128128
Jobs = 29
129129
)
@@ -146,12 +146,6 @@ func main() {
146146
log.Fatalf("%s\n", err.Error())
147147
}
148148
log.Println("文件上传成功!!")
149-
150-
err = req.HeadFile(KeyName)
151-
if err != nil {
152-
log.Fatalf("%s\n", err.Error())
153-
}
154-
log.Printf(" %s", req.LastResponseHeader)
155149
}
156150
```
157151
</div>
@@ -172,9 +166,9 @@ import (
172166
)
173167

174168
const (
175-
ConfigFile = ""
176-
FilePath = ""
177-
KeyName = ""
169+
ConfigFile = "config.json"
170+
FilePath = "FakeBigFile.txt"
171+
KeyName = "FakeBigFile.txt"
178172
MimeType = ""
179173
)
180174

@@ -195,7 +189,7 @@ func main() {
195189
if err != nil {
196190
panic(err.Error())
197191
}
198-
err = req.IOMultipartAsyncUpload(f, KeyName, MimeType)
192+
err = req.IOMutipartAsyncUpload(f, KeyName, MimeType)
199193
if err != nil {
200194
log.Fatalf("%s\n", err.Error())
201195
}
@@ -234,9 +228,9 @@ import (
234228
)
235229

236230
const (
237-
ConfigFile = ""
238-
FilePath = ""
239-
KeyName = ""
231+
ConfigFile = "config.json"
232+
FilePath = "FakeBigFile.txt"
233+
KeyName = "FakeBigFile.txt"
240234
MimeType = ""
241235
)
242236

collections/_go-sdk/初始化请求.md

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,29 @@ SDK 提供`NewBucketRequest`方法用于创建一个bucket 的 request实例,
2222
```go
2323
package main
2424

25-
import ufsdk "github.com/ufilesdk-dev/ufile-gosdk"
25+
import (
26+
"context"
27+
ufsdk "github.com/ufilesdk-dev/ufile-gosdk"
28+
"time"
29+
)
2630

2731
func main() {
2832
config, err := ufsdk.LoadConfig("config.json")
2933
if err != nil {
3034
panic(err.Error())
3135
}
3236

33-
// 新建管理 bucket 的 request
37+
// 新建管理 Bucket 的 request
3438
req, err := ufsdk.NewBucketRequest(config, nil)
3539
if err != nil {
3640
panic(err.Error())
3741
}
38-
42+
3943
// 设置超时时间
40-
req.Context, _ = context.WithTimeout(context.Background(), time.Second * 10)
44+
ctx, cancel := context.WithTimeout(context.Background(), time.Second * 10)
45+
defer cancel()
46+
req.Context = ctx
4147

42-
4348
// do something to manage bucket with req
4449
}
4550
```
@@ -65,7 +70,11 @@ SDK 提供`NewFileRequest`和`NewFileRequestWithHeader`方法用于创建一个
6570
```go
6671
package main
6772

68-
import ufsdk "github.com/ufilesdk-dev/ufile-gosdk"
73+
import (
74+
"context"
75+
ufsdk "github.com/ufilesdk-dev/ufile-gosdk"
76+
"time"
77+
)
6978

7079
func main() {
7180
config, err := ufsdk.LoadConfig("config.json")
@@ -80,8 +89,10 @@ func main() {
8089
}
8190

8291
// 设置超时时间
83-
req.Context, _ = context.WithTimeout(context.Background(), time.Second * 10)
84-
92+
ctx, cancel := context.WithTimeout(context.Background(), time.Second * 10)
93+
defer cancel()
94+
req.Context = ctx
95+
8596
// do something to manage file with req
8697
}
8798
```
@@ -95,7 +106,11 @@ func main() {
95106
```go
96107
package main
97108

98-
import ufsdk "github.com/ufilesdk-dev/ufile-gosdk"
109+
import (
110+
ufsdk "github.com/ufilesdk-dev/ufile-gosdk"
111+
"net/http"
112+
"time"
113+
)
99114

100115
func main() {
101116
config, err := ufsdk.LoadConfig("config.json")
@@ -105,13 +120,14 @@ func main() {
105120

106121
// 自定义cient创建请求
107122
client := &http.Client{}
108-
client.Timeout = time.Second * 5
109-
req, err := ufsdk.NewFileRequest (config, cient)
123+
client.Timeout = time.Second * 1
124+
req, err := ufsdk.NewFileRequest(config, client)
110125
if err != nil {
111126
panic(err.Error())
112127
}
113128

114129
// do something to manage file with req
130+
115131
}
116132
```
117133
</div>
@@ -128,10 +144,14 @@ func main() {
128144

129145
自定义Http Header创建请求示例:
130146
<div class="copyable" markdown="1">
147+
131148
```go
132149
package main
133150

134-
import ufsdk "github.com/ufilesdk-dev/ufile-gosdk"
151+
import (
152+
ufsdk "github.com/ufilesdk-dev/ufile-gosdk"
153+
"net/http"
154+
)
135155

136156
func main() {
137157
config, err := ufsdk.LoadConfig("config.json")
@@ -141,15 +161,14 @@ func main() {
141161

142162
// 自定义Http Header创建请求
143163
header := make(http.Header)
144-
header.Add("X-Ufile-Storage-Class", "ARCHIVE")
164+
header.Add("X-Ufile-Storage-Class", "ARCHIVE")
145165
req, err := ufsdk.NewFileRequestWithHeader(config, header, nil)
146166
if err != nil {
147167
panic(err.Error())
148168
}
149169

150170
// do something to manage file with req
151171
}
152-
153172
```
154173
</div>
155174

0 commit comments

Comments
 (0)