Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
bwallet
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Go
bwallet
Commits
02f90c5a
Commit
02f90c5a
authored
Dec 25, 2019
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
648438c7
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
63 additions
and
32 deletions
+63
-32
excel.go
pkg/export/excel.go
+0
-20
setting.go
pkg/setting/setting.go
+1
-0
upload.go
routers/api/upload.go
+9
-0
upload.go
routers/api/v1/upload.go
+49
-10
router.go
routers/router.go
+4
-2
No files found.
pkg/export/excel.go
deleted
100644 → 0
View file @
648438c7
package
export
import
"bwallet/pkg/setting"
const
EXT
=
".xlsx"
// GetExcelFullUrl get the full access path of the Excel file
func
GetExcelFullUrl
(
name
string
)
string
{
return
setting
.
AppSetting
.
PrefixUrl
+
"/"
+
GetExcelPath
()
+
name
}
// GetExcelPath get the relative save path of the Excel file
func
GetExcelPath
()
string
{
return
setting
.
AppSetting
.
ExportSavePath
}
// GetExcelFullPath Get the full save path of the Excel file
func
GetExcelFullPath
()
string
{
return
setting
.
AppSetting
.
RuntimeRootPath
+
GetExcelPath
()
}
pkg/setting/setting.go
View file @
02f90c5a
...
...
@@ -84,6 +84,7 @@ func Setup() {
mapTo
(
"server"
,
ServerSetting
)
mapTo
(
"database"
,
DatabaseSetting
)
mapTo
(
"redis"
,
RedisSetting
)
mapTo
(
"oss"
,
OssSetting
)
AppSetting
.
ImageMaxSize
=
AppSetting
.
ImageMaxSize
*
1024
*
1024
ServerSetting
.
ReadTimeout
=
ServerSetting
.
ReadTimeout
*
time
.
Second
...
...
routers/api/upload.go
View file @
02f90c5a
...
...
@@ -9,6 +9,7 @@ import (
"bwallet/pkg/e"
"bwallet/pkg/logging"
"bwallet/pkg/upload"
"fmt"
)
// @Summary Import Image
...
...
@@ -36,6 +37,12 @@ func UploadImage(c *gin.Context) {
savePath
:=
upload
.
GetImagePath
()
src
:=
fullPath
+
imageName
//fmt.Println(imageName)
//fmt.Println(fullPath)
//fmt.Println(savePath)
//fmt.Println(src)
//os.Exit(0)
if
!
upload
.
CheckImageExt
(
imageName
)
||
!
upload
.
CheckImageSize
(
file
)
{
appG
.
Response
(
http
.
StatusBadRequest
,
e
.
ERROR_UPLOAD_CHECK_IMAGE_FORMAT
,
nil
)
return
...
...
@@ -54,6 +61,8 @@ func UploadImage(c *gin.Context) {
return
}
fmt
.
Println
(
upload
.
GetImageFullUrl
(
imageName
))
fmt
.
Println
(
savePath
+
imageName
)
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
map
[
string
]
string
{
"image_url"
:
upload
.
GetImageFullUrl
(
imageName
),
"image_save_url"
:
savePath
+
imageName
,
...
...
routers/api/v1/upload.go
View file @
02f90c5a
...
...
@@ -6,13 +6,19 @@ import (
"bwallet/pkg/app"
"bwallet/pkg/e"
"bwallet/pkg/setting"
"bwallet/pkg/upload"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
"fmt"
"os"
)
func
Upload
Image
(
c
*
gin
.
Context
)
{
func
Upload
(
c
*
gin
.
Context
)
{
appG
:=
app
.
Gin
{
C
:
c
}
accessKeyId
:=
setting
.
OssSetting
.
AccessKeyId
accessKeySecret
:=
setting
.
OssSetting
.
AccessKeySecret
endpoint
:=
setting
.
OssSetting
.
Endpoint
bucketName
:=
setting
.
OssSetting
.
Bucket
file
,
image
,
err
:=
c
.
Request
.
FormFile
(
"image"
)
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR
,
nil
)
...
...
@@ -24,19 +30,52 @@ func UploadImage(c *gin.Context) {
return
}
accessKeyId
:=
setting
.
OssSetting
.
AccessKeyId
accessKeySecret
:=
setting
.
OssSetting
.
AccessKeySecret
endpoint
:=
setting
.
OssSetting
.
Endpoint
//bucket := setting.OssSetting.Bucket
imageName
:=
upload
.
GetImageName
(
image
.
Filename
)
fullPath
:=
upload
.
GetImageFullPath
()
//savePath := upload.GetImagePath()
src
:=
fullPath
+
imageName
if
!
upload
.
CheckImageExt
(
imageName
)
||
!
upload
.
CheckImageSize
(
file
)
{
appG
.
Response
(
http
.
StatusBadRequest
,
e
.
ERROR_UPLOAD_CHECK_IMAGE_FORMAT
,
nil
)
return
}
err
=
upload
.
CheckImage
(
fullPath
)
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_UPLOAD_CHECK_IMAGE_FAIL
,
nil
)
return
}
if
err
:=
c
.
SaveUploadedFile
(
image
,
src
);
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_UPLOAD_SAVE_IMAGE_FAIL
,
nil
)
return
}
client
,
err
:=
oss
.
New
(
endpoint
,
accessKeyId
,
accessKeySecret
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
os
.
Exit
(
0
)
appG
.
Response
(
http
.
StatusBadRequest
,
e
.
INVALID_PARAMS
,
nil
)
return
}
fmt
.
Println
(
client
)
os
.
Exit
(
0
)
bucket
,
err
:=
client
.
Bucket
(
bucketName
)
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusBadRequest
,
e
.
INVALID_PARAMS
,
nil
)
return
}
uploaddir
:=
"upload/test"
objectName
:=
fmt
.
Sprintf
(
"%s/%s"
,
uploaddir
,
imageName
)
//完整的oss路径
err
=
bucket
.
PutObjectFromFile
(
objectName
,
upload
.
GetImageFullUrl
(
imageName
))
if
err
!=
nil
{
fmt
.
Println
(
"aaaaaa"
)
fmt
.
Println
(
err
)
return
}
var
resultfile
=
objectName
fmt
.
Println
(
imageName
)
fmt
.
Println
(
resultfile
)
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
map
[
string
]
string
{
"image_url"
:
resultfile
,
"image_name"
:
imageName
,
})
}
routers/router.go
View file @
02f90c5a
...
...
@@ -6,6 +6,8 @@ import (
"bwallet/routers/api"
"bwallet/routers/api/v1"
"bwallet/middleware/auth"
"net/http"
"bwallet/pkg/upload"
)
func
InitRouter
()
*
gin
.
Engine
{
...
...
@@ -15,7 +17,7 @@ func InitRouter() *gin.Engine {
r
.
Use
(
gin
.
Recovery
())
//
r.StaticFS("/upload/images", http.Dir(upload.GetImageFullPath()))
r
.
StaticFS
(
"/upload/images"
,
http
.
Dir
(
upload
.
GetImageFullPath
()))
//r.StaticFS("/qrcode", http.Dir(qrcode.GetQrCodeFullPath()))
r
.
POST
(
"/auth"
,
api
.
GetAuth
)
...
...
@@ -25,7 +27,7 @@ func InitRouter() *gin.Engine {
api
.
Use
(
auth
.
AUTH
())
{
api
.
POST
(
"/upload"
,
v1
.
UploadImage
)
//api.POST("/upload",v1.Upload
)
api
.
GET
(
"/coins"
,
v1
.
GetCoins
)
api
.
POST
(
"/coin"
,
v1
.
AddCoin
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment