|
|
|
@ -27,7 +27,7 @@ enum EnvironmentType {
|
|
|
|
|
export class ObjectsService { |
|
|
|
|
|
|
|
|
|
static readonly c_apiRoot = "/api/Objects/";//普通上传的API根路径
|
|
|
|
|
static apiRoot_Multipart = "/api/";//分块上传的API根路径
|
|
|
|
|
static readonly c_apiRoot_Multipart = "/api/";//分块上传的API根路径
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 当前所处环境(打包前根据需要设置) |
|
|
|
@ -88,7 +88,7 @@ export class ObjectsService {
|
|
|
|
|
// return this.http.post(ObjectsService.baseUrl + extensionPath, formData);
|
|
|
|
|
let data = { keepOriginalName: 'true', filename: file.name } |
|
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
|
this.http.post(ObjectsService.apiRoot_Multipart + "NewMultipartUpload/" + this.getBucketName() + extensionPath, {}, { params: data }).subscribe(async (data: any) => { //初始化分段上传
|
|
|
|
|
this.http.post(ObjectsService.c_apiRoot_Multipart + "NewMultipartUpload/" + this.getBucketName() + extensionPath, {}, { params: data }).subscribe(async (data: any) => { //初始化分段上传
|
|
|
|
|
let instance = this; |
|
|
|
|
let objectName = data.objectName |
|
|
|
|
let uploadId = data.uploadId |
|
|
|
@ -107,7 +107,7 @@ export class ObjectsService {
|
|
|
|
|
//同步写法实现异步调用
|
|
|
|
|
let result = await new Promise((resolve, reject) => { |
|
|
|
|
// await 需要后面返回一个 promise 对象
|
|
|
|
|
this.http.post(ObjectsService.apiRoot_Multipart + `MultipartUpload/${instance.getBucketName()}${objectName}?uploadId=${uploadId}&partNumber=${i + 1}`, formData).subscribe((data: any) => { |
|
|
|
|
this.http.post(ObjectsService.c_apiRoot_Multipart + `MultipartUpload/${instance.getBucketName()}${objectName}?uploadId=${uploadId}&partNumber=${i + 1}`, formData).subscribe((data: any) => { |
|
|
|
|
let msg = { "partNumber": data.partNumber || null, "eTag": data.eTag || null } |
|
|
|
|
resolve(msg) // 调用 promise 内置方法处理成功
|
|
|
|
|
}) |
|
|
|
@ -117,7 +117,7 @@ export class ObjectsService {
|
|
|
|
|
if (PartNumberETag.length === allSlice) { //分块上传完成
|
|
|
|
|
let data = PartNumberETag |
|
|
|
|
let paramsData = { uploadId: uploadId }; |
|
|
|
|
let path = ObjectsService.apiRoot_Multipart + `CompleteMultipartUpload/${instance.getBucketName()}` + objectName; |
|
|
|
|
let path = ObjectsService.c_apiRoot_Multipart + `CompleteMultipartUpload/${instance.getBucketName()}` + objectName; |
|
|
|
|
this.http.post(path, data, { params: paramsData }).subscribe(data => { |
|
|
|
|
let objData: any = new Object(); |
|
|
|
|
objData.fileName = file.name; |
|
|
|
|