本文整理匯總了TypeScript中file-box.FileBox.toBase64方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript FileBox.toBase64方法的具體用法?TypeScript FileBox.toBase64怎麽用?TypeScript FileBox.toBase64使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類file-box.FileBox
的用法示例。
在下文中一共展示了FileBox.toBase64方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: contactAvatar
public async contactAvatar(contactId: string, file?: FileBox): Promise<void | FileBox> {
log.verbose('PuppetPadchat', 'contactAvatar(%s%s)',
contactId,
file ? (', ' + file.name) : '',
)
/**
* 1. set avatar for user self
*/
if (file) {
if (contactId !== this.selfId()) {
throw new Error('can not set avatar for others')
}
if (!this.padchatManager) {
throw new Error('no padchat manager')
}
await this.padchatManager.WXSetHeadImage(await file.toBase64())
return
}
/**
* 2. get avatar
*/
const payload = await this.contactPayload(contactId)
if (!payload.avatar) {
throw new Error('no avatar')
}
const fileBox = FileBox.fromUrl(
payload.avatar,
`wechaty-contact-avatar-${payload.name}.jpg`,
)
return fileBox
}
示例2: messageSendFile
public async messageSendFile(
receiver : Receiver,
file : FileBox,
): Promise<void> {
log.verbose('PuppetPadchat', 'messageSend("%s", %s)', JSON.stringify(receiver), file)
// Send to the Room if there's a roomId
const id = receiver.roomId || receiver.contactId
if (!id) {
throw new Error('no id!')
}
if (!this.padchatManager) {
throw new Error('no padchat manager')
}
const type = file.mimeType || path.extname(file.name)
switch (type) {
case '.slk':
// 發送語音消息(微信silk格式語音)
await this.padchatManager.WXSendVoice(
id,
await file.toBase64(),
60,
)
break
default:
await this.padchatManager.WXSendImage(
id,
await file.toBase64(),
)
break
}
}