
import ALI from '@/api/ali.js'
/**
 * @param {*} keyName 新的图片名称
 * @param {*} file   上传的图片路径
 * @param {*} success 回调函数
 */
let upload = (keyName, file, success) => {
    ALI.getFormDataParams().then(res => {
        let host = "https://birdseye.oss-cn-guangzhou.aliyuncs.com/"
        let key = "birdseye-look-mini/" + keyName
        uni.uploadFile({
            url: host,
            filePath: file,
            name: 'file', // 必须填file。
            formData: {
                key,
                ...res // 使用STS签名时必传。
            },
            success: (res) => {
                if (res.statusCode === 204) {
					uni.showToast({
						title: '上传成功',
						icon: 'none',
						duration: 2000
					});
                    console.log(res)
                    res.key = key
                    success && success(res)
                }
            },
            fail: err => {
				uni.showToast({
					title: '上传失败',
					icon: 'none',
					duration: 2000
				});
                console.log(err);
            }
        });
    })
}
export default upload