|
@@ -1,6 +1,6 @@
|
|
let bucket; //aws上传接口
|
|
let bucket; //aws上传接口
|
|
let bucketname = "ccrb"; //桶
|
|
let bucketname = "ccrb"; //桶
|
|
-const partsize = 1 * 1024 * 1024; // 1MB
|
|
|
|
|
|
+const partsize = 5 * 1024 * 1024; // 5MB
|
|
|
|
|
|
//--------------------------分断上传保证稳定性
|
|
//--------------------------分断上传保证稳定性
|
|
//初始化上传
|
|
//初始化上传
|
|
@@ -21,10 +21,12 @@ async function init() {
|
|
}
|
|
}
|
|
|
|
|
|
//初始化上传入口
|
|
//初始化上传入口
|
|
-async function initMultipartUpload(key) {
|
|
|
|
|
|
+async function initMultipartUpload(key, file) {
|
|
const params = {
|
|
const params = {
|
|
Bucket: bucketname,
|
|
Bucket: bucketname,
|
|
- Key: key
|
|
|
|
|
|
+ Key: key,
|
|
|
|
+ ContentType: file.type,
|
|
|
|
+ "ACL": "public-read"
|
|
};
|
|
};
|
|
//创建一个续传通道
|
|
//创建一个续传通道
|
|
const data = await bucket.createMultipartUpload(params).promise();
|
|
const data = await bucket.createMultipartUpload(params).promise();
|
|
@@ -74,7 +76,7 @@ async function uploadFile(file, folderid) {
|
|
try {
|
|
try {
|
|
init(); // 初始化aws接口
|
|
init(); // 初始化aws接口
|
|
// 初始化分块上传
|
|
// 初始化分块上传
|
|
- uploadid = await initMultipartUpload(keyname);
|
|
|
|
|
|
+ uploadid = await initMultipartUpload(keyname, file);
|
|
// 分块上传文件
|
|
// 分块上传文件
|
|
let parts = [];
|
|
let parts = [];
|
|
let start = 0;
|
|
let start = 0;
|
|
@@ -200,7 +202,7 @@ async function awsupload(file, folderid, filestate) {
|
|
}
|
|
}
|
|
//不存在,上传新的
|
|
//不存在,上传新的
|
|
else {
|
|
else {
|
|
- const uploadid = await initMultipartUpload(key); //初始化文件上传
|
|
|
|
|
|
+ const uploadid = await initMultipartUpload(key, file); //初始化文件上传
|
|
return await awsuploadpart(filestate, file, uploadid, [], key);
|
|
return await awsuploadpart(filestate, file, uploadid, [], key);
|
|
}
|
|
}
|
|
}
|
|
}
|