提交网络请求
This commit is contained in:
parent
7f8c81dc66
commit
f44649d8dc
@ -4,8 +4,8 @@ import { CryptoJS } from '@ohos/crypto-js';
|
||||
import { logger } from './logger';
|
||||
import image from '@ohos.multimedia.image';
|
||||
import fs from '@ohos.file.fs';
|
||||
|
||||
|
||||
import { fileIo } from '@kit.CoreFileKit';
|
||||
import util from '@ohos.util';
|
||||
export class ChangeUtil {
|
||||
/**
|
||||
* 将HashMap转成JsonString
|
||||
@ -57,6 +57,19 @@ export class ChangeUtil {
|
||||
return reg2.test(password);
|
||||
}
|
||||
|
||||
|
||||
static async convertUriToBase64(uri: string): Promise<string> {
|
||||
// 打开文件并读取数据
|
||||
const file = fileIo.openSync(uri, fileIo.OpenMode.READ_ONLY);
|
||||
const stat = await fileIo.stat(file.fd);
|
||||
const buffer = new ArrayBuffer(stat.size);
|
||||
fileIo.readSync(file.fd, buffer);
|
||||
fileIo.closeSync(file);
|
||||
|
||||
// 编码为 Base64
|
||||
const base64Helper = new util.Base64Helper();
|
||||
return base64Helper.encodeToStringSync(new Uint8Array(buffer));
|
||||
}
|
||||
/**
|
||||
* 将图片转换为base64字符串
|
||||
* @param imageUri 图片URI
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user