import MessageType from "../utils/MessageType";
import FetchRequest from '@/api/FetchRequest';
import Auth from '@/api/Auth';
import VimConfig from "@/config/VimConfig";

const upload = (tempFilePath : string) => {
	return new Promise((resolve, reject) => {
		uni.uploadFile({
			url: `${FetchRequest.getHost()}/${VimConfig.uploadType}/upload`, //仅为示例，非真实的接口地址
			filePath: tempFilePath,
			name: 'file',
			header: {
				"Access-Control-Allow-Origin": "*",
				"Authorization": `Bearer ${Auth.getToken()}`,
			},
			formData: {
				'type': MessageType.voice
			},
			success: (res) => {
				const data = JSON.parse(res.data)
				resolve(data)
			},
			fail: (err) => {
				reject(err)
			}
		})
	})
}
export default upload
