|
@@ -179,15 +179,20 @@ const handleUploadToMinIO=(file,fileName,options={})=>{
|
|
|
|
|
|
minioClient.bucketExists(res.Data.Bucketname, function (err, exists) {
|
|
minioClient.bucketExists(res.Data.Bucketname, function (err, exists) {
|
|
if (err) {
|
|
if (err) {
|
|
- throw "minio 查看桶是否存在失败"+err
|
|
|
|
- // return console.log(err);
|
|
|
|
|
|
+ Message.warning("上传失败,请刷新重试");
|
|
|
|
+ reject('minio 查看桶是否存在失败')
|
|
|
|
+ // throw "minio 查看桶是否存在失败"+err
|
|
|
|
+ return console.error("minio 查看桶是否存在失败"+err);
|
|
}
|
|
}
|
|
if (!exists) {
|
|
if (!exists) {
|
|
// 不存在桶,创建桶
|
|
// 不存在桶,创建桶
|
|
console.log("桶不存在,先创建桶",res.Data.Bucketname);
|
|
console.log("桶不存在,先创建桶",res.Data.Bucketname);
|
|
minioClient.makeBucket(res.Data.Bucketname, res.Data.RegionId,function (err) {
|
|
minioClient.makeBucket(res.Data.Bucketname, res.Data.RegionId,function (err) {
|
|
if (err) {
|
|
if (err) {
|
|
- throw "minio 创建桶失败"+err
|
|
|
|
|
|
+ Message.warning("上传失败,请刷新重试");
|
|
|
|
+ reject('minio 创建桶失败')
|
|
|
|
+ return console.error("minio 创建桶失败"+err);
|
|
|
|
+ // throw "minio 创建桶失败"+err
|
|
}
|
|
}
|
|
|
|
|
|
let reader = new FileReader();
|
|
let reader = new FileReader();
|
|
@@ -201,7 +206,10 @@ const handleUploadToMinIO=(file,fileName,options={})=>{
|
|
// console.log(bufferStream);
|
|
// console.log(bufferStream);
|
|
minioClient.putObject(res.Data.Bucketname, fileName, bufferStream,file.size, metaData, function (err, etag) {
|
|
minioClient.putObject(res.Data.Bucketname, fileName, bufferStream,file.size, metaData, function (err, etag) {
|
|
if (err){
|
|
if (err){
|
|
- throw "上传到minio失败:"+err
|
|
|
|
|
|
+ Message.warning("上传失败,请刷新重试");
|
|
|
|
+ reject('上传到minio失败')
|
|
|
|
+ return console.error("上传到minio失败"+err);
|
|
|
|
+ // throw "上传到minio失败:"+err
|
|
}
|
|
}
|
|
|
|
|
|
})
|
|
})
|
|
@@ -220,7 +228,10 @@ const handleUploadToMinIO=(file,fileName,options={})=>{
|
|
bufferStream.end(Buffer.from(dataurl))
|
|
bufferStream.end(Buffer.from(dataurl))
|
|
minioClient.putObject(res.Data.Bucketname, fileName, bufferStream, metaData, function (err, etag) {
|
|
minioClient.putObject(res.Data.Bucketname, fileName, bufferStream, metaData, function (err, etag) {
|
|
if (err){
|
|
if (err){
|
|
- throw "上传到minio失败:"+err
|
|
|
|
|
|
+ Message.warning("上传失败,请刷新重试");
|
|
|
|
+ reject('上传到minio失败')
|
|
|
|
+ return console.error("上传到minio失败"+err);
|
|
|
|
+ // throw "上传到minio失败:"+err
|
|
}
|
|
}
|
|
let fileUrl = fileName.startsWith('/')?res.Data.ImgHost+fileName:res.Data.ImgHost+"/"+fileName
|
|
let fileUrl = fileName.startsWith('/')?res.Data.ImgHost+fileName:res.Data.ImgHost+"/"+fileName
|
|
resolve(fileUrl)
|
|
resolve(fileUrl)
|
|
@@ -232,7 +243,7 @@ const handleUploadToMinIO=(file,fileName,options={})=>{
|
|
console.error(error);
|
|
console.error(error);
|
|
if (error.name !== "cancel") {
|
|
if (error.name !== "cancel") {
|
|
//不是取消上传的则给错误提示
|
|
//不是取消上传的则给错误提示
|
|
- this.$message.warning("上传失败,请刷新重试");
|
|
|
|
|
|
+ Message.warning("上传失败,请刷新重试");
|
|
}
|
|
}
|
|
reject(error)
|
|
reject(error)
|
|
}
|
|
}
|
|
@@ -240,6 +251,10 @@ const handleUploadToMinIO=(file,fileName,options={})=>{
|
|
}
|
|
}
|
|
//https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#constructor-property
|
|
//https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#constructor-property
|
|
const handleUploadToS3=(file,fileName,options={})=>{
|
|
const handleUploadToS3=(file,fileName,options={})=>{
|
|
|
|
+ /**
|
|
|
|
+ * options 里面包含了一些配置,包括分片上传等…… 测试服目前还没有AWS3 的对象存储器,无法测试,暂不进行配置
|
|
|
|
+ * s3Client.upload(params={},[options={}],[callback])
|
|
|
|
+ */
|
|
return new Promise(async(resolve,reject)=>{
|
|
return new Promise(async(resolve,reject)=>{
|
|
const res=await getOSSSign({StorageSource:3})
|
|
const res=await getOSSSign({StorageSource:3})
|
|
if(res.Ret!==200) reject("获取s3签名错误,res.Ret="+res.Ret)
|
|
if(res.Ret!==200) reject("获取s3签名错误,res.Ret="+res.Ret)
|
|
@@ -294,10 +309,12 @@ const handleUploadToS3=(file,fileName,options={})=>{
|
|
Body: file,
|
|
Body: file,
|
|
ACL: "public-read",
|
|
ACL: "public-read",
|
|
Key: fileName
|
|
Key: fileName
|
|
- },options, function (err, data) {
|
|
|
|
|
|
+ }, function (err, data) {
|
|
if (err) {
|
|
if (err) {
|
|
- console.log("Error! err =====> ", err);
|
|
|
|
- throw new Error("上传到s3失败!")
|
|
|
|
|
|
+ Message.warning("上传失败,请刷新重试");
|
|
|
|
+ reject('上传到s3失败')
|
|
|
|
+ return console.log("上传到s3失败! Error! err =====> ", err);
|
|
|
|
+ // throw new Error("上传到s3失败!")
|
|
} else {
|
|
} else {
|
|
let url = data['Location'];
|
|
let url = data['Location'];
|
|
console.log("Successfully uploaded! URL =====> ", url);
|
|
console.log("Successfully uploaded! URL =====> ", url);
|
|
@@ -309,7 +326,7 @@ const handleUploadToS3=(file,fileName,options={})=>{
|
|
console.error(error);
|
|
console.error(error);
|
|
if (error.name !== "cancel") {
|
|
if (error.name !== "cancel") {
|
|
//不是取消上传的则给错误提示
|
|
//不是取消上传的则给错误提示
|
|
- this.$message.warning("上传失败,请刷新重试");
|
|
|
|
|
|
+ Message.warning("上传失败,请刷新重试");
|
|
}
|
|
}
|
|
reject(error)
|
|
reject(error)
|
|
}
|
|
}
|