-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f3db928
commit 5fbe48a
Showing
10 changed files
with
203 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,15 @@ | ||
# qiniuyun_upload_tools | ||
七牛云上传工具 | ||
# config | ||
```json | ||
{ | ||
"access_key": "************", // ak | ||
"secret_key": "***************", // sk | ||
"zone": 0, //存储空间所在区域,0:华东, 1:华北, 2:华南, 3:北美 | ||
"Bucket": "hanyajun", //存储空间名 | ||
"use_https": false,//是否使用https | ||
"bucket": "http://cdn.hanyajun.com/" | ||
} | ||
|
||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"access_key": "*******", | ||
"secret_key": "*******", | ||
"zone": 0, | ||
"Bucket": "hanyajun", | ||
"use_https": false, | ||
"bucket": "http://cdn.hanyajun.com/" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"html/template" | ||
"io/ioutil" | ||
"os" | ||
) | ||
|
||
/* | ||
* @Author:hanyajun | ||
* @Date:2019/5/22 0:01 | ||
* @Name:cmd | ||
* @Function: | ||
*/ | ||
|
||
func main() { | ||
fileList := readDirectory("need_upload_data") | ||
printFileList(fileList) | ||
t, _ := template.ParseFiles("templates/success.html") | ||
fmt.Println(t.Name()) | ||
fileObj, err := os.OpenFile("success.html", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644) | ||
if err != nil { | ||
fmt.Println("Failed to open the file", err.Error()) | ||
os.Exit(2) | ||
} | ||
_ = t.Execute(fileObj, fileList) | ||
} | ||
|
||
func readDirectory(dir string) (fl []string) { | ||
|
||
files, _ := ioutil.ReadDir(dir) | ||
|
||
var fileList []string | ||
fileList = make([]string, len(files)) | ||
|
||
i := 0 | ||
for _, file := range files { | ||
if file.IsDir() { | ||
continue | ||
} else { | ||
fileList[i] = file.Name() | ||
i++ | ||
} | ||
} | ||
return fileList | ||
} | ||
|
||
func printFileList(fl []string) { | ||
for i := 0; i < len(fl); i++ { | ||
fmt.Println(fl[i]) | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package pkg | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
) | ||
|
||
/* | ||
* @Author:hanyajun | ||
* @Date:2019/5/25 0:48 | ||
* @Name:pkg | ||
* @Function: | ||
*/ | ||
|
||
/* | ||
* 读取目录内的文件 | ||
*/ | ||
func readDirectory(dir string) (fl []string) { | ||
|
||
files, _ := ioutil.ReadDir(dir) | ||
|
||
var fileList []string | ||
fileList = make([]string, len(files)) | ||
|
||
i := 0 | ||
for _, file := range files { | ||
if file.IsDir() { | ||
continue | ||
} else { | ||
fileList[i] = file.Name() | ||
i++ | ||
} | ||
} | ||
return fileList | ||
} | ||
|
||
func printFileList(fl []string) { | ||
for i := 0; i < len(fl); i++ { | ||
fmt.Println(fl[i]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package pkg | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/qiniu/api.v7/auth/qbox" | ||
"github.com/qiniu/api.v7/storage" | ||
"time" | ||
) | ||
|
||
/* | ||
* @Author:hanyajun | ||
* @Date:2019/5/22 15:16 | ||
* @Name:pkg | ||
* @Function: | ||
*/ | ||
|
||
type QiNiuClient struct { | ||
AccessKey string `json:"access_key"` | ||
SecretKey string `json:"secret_key"` | ||
Bucket string `json:"bucket"` | ||
Zone int `json:"zone"` //0:华东, 1:华北, 2:华南, 3:北美 | ||
UseHTTPS bool `json:"use_https"` | ||
UseCdnDomains bool `json:"use_cdn_domains"` | ||
Domain string `json:"domain"` | ||
} | ||
|
||
func NewClient(accessKey, secretKey, bucket string, Zone int, useHttps, useCdnDomains bool, domain string) *QiNiuClient { | ||
return &QiNiuClient{ | ||
AccessKey: accessKey, | ||
SecretKey: secretKey, | ||
Bucket: bucket, | ||
Zone: Zone, | ||
UseHTTPS: useHttps, | ||
UseCdnDomains: useCdnDomains, | ||
Domain: domain, | ||
} | ||
} | ||
|
||
func (client *QiNiuClient) UploadFile(fileList []string) { | ||
putPolicy := storage.PutPolicy{ | ||
Scope: client.Bucket, | ||
} | ||
mac := qbox.NewMac(client.AccessKey, client.SecretKey) | ||
upToken := putPolicy.UploadToken(mac) | ||
cfg := storage.Config{} | ||
// 空间对应的机房 | ||
cfg.Zone = &storage.ZoneHuadong | ||
// 是否使用https域名 | ||
cfg.UseHTTPS = client.UseHTTPS | ||
// 上传是否使用CDN上传加速 | ||
cfg.UseCdnDomains = client.UseCdnDomains | ||
// 构建表单上传的对象 | ||
formUploader := storage.NewFormUploader(&cfg) | ||
ret := storage.PutRet{} | ||
// 可选配置 | ||
putExtra := storage.PutExtra{ | ||
//Params: map[string]string{ | ||
// "x:name": "github logo", | ||
//}, | ||
} | ||
key := time.Now().Unix() + "_" | ||
err := formUploader.PutFile(context.Background(), &ret, upToken, key, localFile, &putExtra) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
fmt.Println(ret.Key, ret.Hash) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset='utf-8'> | ||
<title>上传内容</title> | ||
</head> | ||
<body> | ||
<div> | ||
{{ range . }} | ||
<img src='{{ . }}' height='120' /> <span id='my_url_0'>![]({{ . }})</span> <button class='btn' data-clipboard-target='#my_url_0' style='width:50px;height:30px;'>复制</button><br/> | ||
{{ end }} | ||
|
||
</div> | ||
<script type='text/javascript' src='https://cdn.staticfile.org/clipboard.js/1.5.15/clipboard.min.js'></script> | ||
<script type = 'text/javascript' > | ||
var clipboard = new Clipboard('.btn'); | ||
</script> | ||
</body> | ||
</html> |