非零即为真
非零即为真
  • 发布:2019-04-12 10:11
  • 更新:2021-01-13 23:13
  • 阅读:2120

input 转Object-URL 使用 uni.uploadFile 上传视频

分类:uni-app

详细问题描述

因为现在微信浏览器中无法使用uni-app的选择视频API(用了没有回调),只能用js创建input来上传,官方文档上面这样写到,


然后我去试了下转 Object-URL 使用 uni.uploadFile 上传,

            // 创建input  
            var input = document.createElement('input');  
            input.type = 'file';  
            input.accept="video/*";  
            input.id = 'add_video';  
            this.$refs["add_video"].$el.appendChild(input)  
            input.onchange = (event) => {  
                var file = event.srcElement.files[0];  
                var url = URL.createObjectURL(file);  
                console.log(url);  
                uni.uploadFile({  
                    url: "",  
                    filePath: url,  
                    name: "img",  
                    success: (res) => {  
                        console.log(res);  
                    },  
                })  
            }

但是一直提示文件名后缀错误,让后台打印了一下,结果接收到的文件名是 "file-1555034886211"


有没有大神遇到过,求解啊!

联系方式

[QQ]
806834390

2019-04-12 10:11 负责人:无 分享
已邀请:
6***@qq.com

6***@qq.com

跟你遇到同样的问题了 0202年了 这问题依然存在

  • 非零即为真 (作者)

    .........2020

    只能用xhr上传了

    2020-01-15 08:56

kyxiao2020

kyxiao2020 - 一个前端开发者

自己创建的bloburl就不能上传,报String index out of range: -1

MonikaChen

MonikaChen

const ext = input.files[0].name.split('.').pop().toLowerCase() // 扩展名,小写

你把扩展名也发给后端,后端保存时直接用这个参数作为扩展名保存文件即可

该问题目前已经被锁定, 无法添加新回复