Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
ElectricitySheep
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
黄媛媛
ElectricitySheep
Commits
025935b3
Commit
025935b3
authored
Oct 22, 2020
by
zhengke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加阿里云上传
parent
164522a7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
109 additions
and
49 deletions
+109
-49
index.js
src/plug/index.js
+109
-49
No files found.
src/plug/index.js
View file @
025935b3
...
...
@@ -58,8 +58,8 @@ export default {
let
javaUrl
=
'http://192.168.2.65:8018'
;
// domainUrl = "http://192.168.1.27:8200";
domainUrl
=
"http://192.168.1.5
:8088"
;
//
domainUrl = "http://192.168.1.21";
//domainUrl = "http://192.168.1.13
:8088";
domainUrl
=
"http://192.168.1.21"
;
//domainUrl = "https://localhost:5001";
let
vtUploadUrl
=
"http://192.168.1.214:8120"
;
...
...
@@ -181,6 +181,7 @@ export default {
//上传文件到云存储
Vue
.
prototype
.
UploadFileToTencent
=
function
(
path
,
fileObj
,
callback
)
{
// debugger;
var
upInfo
=
JSON
.
parse
(
localStorage
.
uploadInfo
);
if
(
fileObj
.
type
==
"image/png"
||
fileObj
.
type
==
"image/jpeg"
)
{
let
that
=
this
lrz
(
fileObj
,
{
...
...
@@ -200,19 +201,111 @@ export default {
var
newFile
=
new
File
([
u8arr
],
fileObj
.
name
,
{
type
:
mime
});
that
.
uploadStart
(
path
,
newFile
,
callback
)
if
(
upInfo
.
IsDefault
==
1
){
that
.
uploadStart
(
path
,
newFile
,
callback
)
}
else
{
this
.
Error
(
'请先配置上传'
);
}
}).
catch
(
function
(
error
)
{
that
.
uploadStart
(
path
,
fileObj
,
callback
)
if
(
upInfo
.
IsDefault
==
1
){
if
(
upInfo
.
StoreType
==
1
){
that
.
uploadStart
(
path
,
newFile
,
callback
)
}
if
(
upInfo
.
StoreType
==
3
){
that
.
uploadToAli
(
path
,
newFile
,
callback
)
}
}
else
{
this
.
Error
(
'请先配置上传'
);
}
}).
always
(
function
()
{
//不管成功或失败,都会执行
})
}
else
{
this
.
uploadStart
(
path
,
fileObj
,
callback
)
if
(
upInfo
.
IsDefault
==
1
){
if
(
upInfo
.
StoreType
==
1
){
this
.
uploadStart
(
path
,
fileObj
,
callback
)
}
if
(
upInfo
.
StoreType
==
3
){
this
.
uploadToAli
(
path
,
fileObj
,
callback
)
}
}
else
{
this
.
Error
(
'请先配置上传'
);
}
}
},
Vue
.
prototype
.
uploadStart
=
function
(
path
,
fileObj
,
callback
)
{
var
upInfo
=
JSON
.
parse
(
localStorage
.
uploadInfo
);
if
(
upInfo
.
IsDefault
==
1
){
//获取文件扩展名
var
filename
=
fileObj
.
name
;
var
index
=
filename
.
lastIndexOf
(
"."
);
var
suffix
=
filename
.
substr
(
index
);
var
timestamp1
=
Date
.
parse
(
new
Date
())
+
"_"
+
(
Math
.
ceil
(
Math
.
random
()
*
1000
));
let
str
=
''
;
if
(
this
.
isOnline
())
{
str
=
"/Test"
}
var
newFileName
=
str
+
'/Upload/'
+
path
+
"/"
+
timestamp1
+
""
+
suffix
;
// var uploadMsg = {
// Bucket: "viitto-1301420277",
// Region: "ap-chengdu",
// /* 存储桶所在地域,必须字段 */
// SecretId: "AKIDDPnbIzi8C1eqEOPP8dw6MNAg9H9ldDKd",
// SecretKey: "PdcLtOjslUzNFYdU4OSI1fKtdHpFT2Ob",
// };
var
uploadMsg
=
{
Bucket
:
upInfo
.
Bucket
,
Region
:
upInfo
.
Region
,
SecretId
:
upInfo
.
SecretId
,
SecretKey
:
upInfo
.
SecretKey
,
};
var
COS
=
require
(
'cos-js-sdk-v5'
);
var
cos
=
new
COS
({
SecretId
:
uploadMsg
.
SecretId
,
SecretKey
:
uploadMsg
.
SecretKey
,
});
cos
.
putObject
({
Bucket
:
uploadMsg
.
Bucket
,
Region
:
uploadMsg
.
Region
,
//存储桶所在地域,必须字段
Key
:
newFileName
,
//文件名
StorageClass
:
'STANDARD'
,
Body
:
fileObj
,
// 上传文件对象
onProgress
:
function
(
progressData
)
{}
},
function
(
err
,
data
)
{
if
(
data
&&
data
.
statusCode
==
200
)
{
var
uploadResult
=
{
resultCode
:
1
,
FileName
:
fileObj
.
name
,
FileUrl
:
"http://"
+
data
.
Location
}
if
(
callback
)
{
console
.
log
(
uploadResult
,
'uploadResult'
);
callback
(
uploadResult
);
}
}
else
{
/*上传文件异常*/
console
.
log
(
err
||
data
);
}
});
},
//上传至阿里云
Vue
.
prototype
.
uploadToAli
=
function
(
path
,
fileObj
,
successCall
)
{
var
upInfo
=
JSON
.
parse
(
localStorage
.
uploadInfo
);
var
OSS
=
require
(
'ali-oss'
);
var
oss
=
new
OSS
({
region
:
upInfo
.
Region
,
accessKeyId
:
upInfo
.
SecretId
,
accessKeySecret
:
upInfo
.
SecretKey
,
bucket
:
upInfo
.
Bucket
// region: 'oss-cn-chengdu',
// accessKeyId: 'LTAIwE7l9dImZSa3',
// accessKeySecret: 'j47Ajn0d0WzUCIX8Biyj3P2r8QDltI',
// bucket: 'vt-im-bucket'
})
let
that
=
this
;
let
checkpoint
=
null
;
let
percentage
=
0
;
//获取文件扩展名
var
filename
=
fileObj
.
name
;
var
index
=
filename
.
lastIndexOf
(
"."
);
...
...
@@ -223,50 +316,17 @@ export default {
str
=
"/Test"
}
var
newFileName
=
str
+
'/Upload/'
+
path
+
"/"
+
timestamp1
+
""
+
suffix
;
// var uploadMsg = {
// Bucket: "viitto-1301420277",
// Region: "ap-chengdu",
// /* 存储桶所在地域,必须字段 */
// SecretId: "AKIDDPnbIzi8C1eqEOPP8dw6MNAg9H9ldDKd",
// SecretKey: "PdcLtOjslUzNFYdU4OSI1fKtdHpFT2Ob",
// };
var
uploadMsg
=
{
Bucket
:
upInfo
.
Bucket
,
Region
:
upInfo
.
Region
,
SecretId
:
upInfo
.
SecretId
,
SecretKey
:
upInfo
.
SecretKey
,
};
var
COS
=
require
(
'cos-js-sdk-v5'
);
var
cos
=
new
COS
({
SecretId
:
uploadMsg
.
SecretId
,
SecretKey
:
uploadMsg
.
SecretKey
,
});
cos
.
putObject
({
Bucket
:
uploadMsg
.
Bucket
,
Region
:
uploadMsg
.
Region
,
//存储桶所在地域,必须字段
Key
:
newFileName
,
//文件名
StorageClass
:
'STANDARD'
,
Body
:
fileObj
,
// 上传文件对象
onProgress
:
function
(
progressData
)
{}
},
function
(
err
,
data
)
{
if
(
data
&&
data
.
statusCode
==
200
)
{
var
uploadResult
=
{
resultCode
:
1
,
FileName
:
fileObj
.
name
,
FileUrl
:
"http://"
+
data
.
Location
}
if
(
callback
)
{
callback
(
uploadResult
);
}
}
else
{
/*上传文件异常*/
console
.
log
(
err
||
data
);
// fileName = "/New" + '/' +path+ '/' + fileName + "." + files.name.split('.').pop()
var
result
=
oss
.
multipartUpload
(
newFileName
,
fileObj
,
{
progress
:
function
*
(
p
)
{}
}).
then
(
res
=>
{
var
uploadResult
=
{
resultCode
:
1
,
FileName
:
fileObj
.
name
,
FileUrl
:
res
.
res
.
requestUrls
[
0
]
}
});
}
else
{
this
.
Error
(
'请先配置上传'
);
}
successCall
(
uploadResult
);
})
},
//公用跳转
Vue
.
prototype
.
CommonJump
=
function
(
path
,
obj
)
{
...
...
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