Open leochen-g opened 2 years ago
在file-box包中,我看到对mimeType是有多种取值方式的,那么在wechaty-puppet-wechat中是否可以也进行多种判断来赋值mimeType呢,例如传入的file对象name里能解析出mimeType就使用,解析不出就用file对象中mimeType属性。不知这种方法能否可行呢 @huan ,是否会影响到其他地方
I believe it will be a good solution. PR will welcome.
Good catch and thank you very much for the contribution!
示例图片地址:
http://p3-webcast.douyinpic.com/img/webcast/6927462391257500419~tplv-resize:0:0.image
问题:当我发送一个网络图片地址的时候,后缀名是不包含文件类型的,但是返回的
header
里content-type
是image/jpeg
当使用
const obj = FileBox.fromUrl(url)
直接构造一个obj
对象时,打印出来的mimeType
为空,此时我发现有个ready
函数可以获取header
里的contentType来赋值mimeType
,在FileBox.fromUrl(url)
之后加了一个await obj.ready()
。使用后构造的obj
对象mimeType
是有值的。如下图但是到发送的时候却报错
no MIME Type found on mediaMessage
,起初我以为是file-box
包的问题,但是最后才发现是wechaty-puppet-wechat
里puppet-wechat.ts
有个uploadMedia
方法,这里是直接用name
去取contentType
,并没有使用obj
的mimeType
属性,导致报错no MIME Type found on mediaMessage
解决思路:
在
file-box
包中,我看到对mimeType
是有多种取值方式的,那么在wechaty-puppet-wechat
中是否可以也进行多种判断来赋值mimeType
呢,例如传入的file
对象name
里能解析出mimeType
就使用,解析不出就用file
对象中mimeType
属性。不知这种方法能否可行呢 @huan ,是否会影响到其他地方