上代码:
html部分:
<Upload
accept="audio/ogg,audio/mp3,audio/wav,audio/m4a,audio/flac"
{...defaultUploadProps}
beforeUpload={beforeUpload}
>
<Button type="primary">上传音乐 +</Button>
</Upload>
js部分:
const upload_data = {
token: Cookies.get('token'),
width: 100,
height: 100,
duration: 0,
type: 0,
};
const defaultUploadProps = {
data: () => {
return {
...upload_data,
uid: 1,
token: Cookies.get('token'),
localPath: '',
};
},
action: URL地址,
listType: 'picture',
multiple: true,
onChange: (e) => {
},
};
//上传图片,视频,音频
const beforeUpload = (file) => {
return new Promise((resolve, reject) => {
var reader = new FileReader();
reader.readAsDataURL(file);
console.log(file);
});
};
看html部分,我是可以上传ogg,flac,wav,mp3,m4a格式的音乐的,但是,当我上传mp3格式的音乐的时候,beformUpload事件不触发。
各方查询之后,发现限制文件上传类型的时候,audio/mp3是不对的。。。。。
可以参考:https://www.runoob.com/html/html5-audio.html
解决方式:
只需要修改html即可:
<Upload
accept="audio/ogg,audio/mpeg,audio/wav,audio/m4a,audio/flac"
{...defaultUploadProps}
beforeUpload={beforeUpload}
>
<Button type="primary">上传音乐 +</Button>
</Upload>