oak-frontend-base/lib/utils/upload.native.js

36 lines
1.1 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Upload = void 0;
class Upload {
async uploadFile(file, name, uploadUrl, formData, autoInform, getPercent, method = "POST") {
const isPut = method === "PUT";
if (isPut) {
// S3 预签名上传
const headers = {};
if (file instanceof File) {
headers["Content-Type"] = file.type || "application/octet-stream";
}
const result = await fetch(uploadUrl, {
method: "PUT",
headers,
body: file,
});
return result;
}
else {
// 表单上传
const formData2 = new FormData();
for (const key of Object.keys(formData)) {
formData2.append(key, formData[key]);
}
formData2.append(name || "file", file);
const result = await fetch(uploadUrl, {
method,
body: formData2,
});
return result;
}
}
}
exports.Upload = Upload;