对base64格式的图片进行上传可以通过以下方式实现实现上传。https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-request-V5\#requestuploadfile9https://gitee.com/openharmony-sig/ohos\_axios\#axios-%E5%AE%9E%E4%BE%8Bhttps://developer.huawei.com/consumer/cn/doc/harmonyos-references/remote-communication-rcp-V5\#section1188301010515示例参考:let context: Context = getContext(this); const keyPemConent = context.resourceManager.getRawFileContentSync('testIMG.png') let filesDir: string = context.filesDir let filePath: string = filesDir + 'image1.png' let file = fs.openSync(filePath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); fs.writeSync(file.fd, keyPemConent.buffer); fs.fsyncSync(file.fd); fs.closeSync(file); let headers: rcp.RequestHeaders = { "accept": "multipart/form-data" }; const multiForm1: Record<string, rcp.MultipartFormFieldValue | rcp.MultipartFormFieldValue[]> = {} const multiForm: rcp.MultipartFormFields = { "testImg": { contentType: "image/png", // "text/plain" contentOrPath: filePath, }, } const session = rcp.createSession(); let req = new rcp.Request("http://huawei.com", "POST", headers, multiForm); // let req = new rcp.Request("http://huawei.com", "POST", headers, multiForm1); session.fetch(req).then((response) => { console.info(`${response}`); }).catch((err: BusinessError) => { console.error(`err: err code is ${err.code}, err message is ${err.message}`); });
对base64格式的图片进行上传可以通过以下方式实现实现上传。
https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-request-V5\#requestuploadfile9
https://gitee.com/openharmony-sig/ohos\_axios\#axios-%E5%AE%9E%E4%BE%8B
https://developer.huawei.com/consumer/cn/doc/harmonyos-references/remote-communication-rcp-V5\#section1188301010515
示例参考: