"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Upload = void 0; const promisify_1 = require("./promisify"); class Upload { abortUpload(uploadId) { return false; } abortAllUploads() { } getUploadStatus(uploadId) { return 'not-found'; } getActiveUploads() { return []; } async uploadFile(options) { const { file, name, uploadUrl, formData, isFilePath, method = "POST" } = options; const isPut = method === "PUT"; if (isPut) { if (isFilePath) { return new Promise((resolve, reject) => { const fs = wx.getFileSystemManager(); fs.readFile({ filePath: file, encoding: 'binary', success: res => { resolve(global.fetch(uploadUrl, { method: "PUT", headers: { 'Content-Type': 'application/octet-stream', }, body: res.data, })); }, fail: err => { reject(err); } }); }); } return global.fetch(uploadUrl, { method: "PUT", headers: { 'Content-Type': 'application/octet-stream', }, body: file, }); } else { const wxUploadFile = (0, promisify_1.promisify)(wx.uploadFile); const result = await wxUploadFile({ url: uploadUrl, filePath: file, name: name || 'file', formData: formData, }); return result; } } } exports.Upload = Upload;