import Global from './global.js'
let mpi = {}

//上传图片
mpi.uploadFile = (count = 1) => {
	return new Promise((resolve, reject) => {
		uni.chooseImage({
			count, //默认100
			sizeType: ['compressed'],
			sourceType: ['album', 'camera'],
			success: function(res) {
				if (res.tempFiles[0].size > 3145728){
					uni.showToast({
						title: "上传图片大小不能超过3M",
						icon: "none"
					})
					return;
				} else {
					uni.uploadFile({
						url: `${Global.baseUrl}/putObject`, //仅为示例，非真实的接口地址
						filePath: res.tempFilePaths[0],
						name: 'file',
						success: (uploadFileRes) => {
							resolve(uploadFileRes.data)
						},
						fail: () => {
							reject(err)
						}
					});
				}
			}
		});
	})
}

mpi.uploadVideo = () => {
	return new Promise((resolve, reject) => {
		uni.chooseVideo({
			count:1, //默认100
			sourceType: ['album', 'camera'],
			success: function(res) {
				uni.uploadFile({
					url: `${Global.baseUrl}/putObject`, //仅为示例，非真实的接口地址
					filePath: res.tempFilePath,
					name: 'file',
					success: (uploadFileRes) => {
						resolve(uploadFileRes.data)
					},
					fail: () => {
						reject(err)
					}
				});
			}
		});
	})
}

export default mpi
