refactor(hospital): 重构图片上传功能
- 修改 HosApiUtils.upload 方法,使用原生 MultiFormData 类型 - 更新 HosAuthInfoEditView 中的图片上传逻辑- 在 HttpHelper 中添加 HttpParamsUpload 接口,用于处理上传请求 - 在 FileHelper 中新增 copyFileToCacheDir 方法,用于将文件复制到缓存目录
这个提交包含在:
父节点
aff781423c
当前提交
3c1dcb0782
@ -3,7 +3,7 @@ import http from '@ohos.net.http';
|
|||||||
import { LogHelper } from '../../../../Index';
|
import { LogHelper } from '../../../../Index';
|
||||||
import { SZYXLocalStorageHelper } from '../utils/SZYXLocalStorageHelper';
|
import { SZYXLocalStorageHelper } from '../utils/SZYXLocalStorageHelper';
|
||||||
import { SZYXLocalStorageKeys } from '../utils/SZYXLocalStorageKeys';
|
import { SZYXLocalStorageKeys } from '../utils/SZYXLocalStorageKeys';
|
||||||
import { HttpHelperX, HttpParamsForm, HttpParamsGet, HttpParamsPost } from './HttpHelperX';
|
import { HttpHelperX, HttpParamsForm, HttpParamsGet, HttpParamsPost, HttpParamsUpload } from './HttpHelperX';
|
||||||
import { BusinessError } from '@kit.BasicServicesKit';
|
import { BusinessError } from '@kit.BasicServicesKit';
|
||||||
import { image } from '@kit.ImageKit';
|
import { image } from '@kit.ImageKit';
|
||||||
|
|
||||||
@ -314,7 +314,7 @@ export class HttpHelper {
|
|||||||
* @param apiNo 请求标识,取消请求或者去重使用|考虑做自动重试使用
|
* @param apiNo 请求标识,取消请求或者去重使用|考虑做自动重试使用
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
public upload<T>(params: HttpParamsPost, apiNo?: string, showLog?: boolean): Promise<T> {
|
public upload<T>(params: HttpParamsUpload, apiNo?: string, showLog?: boolean): Promise<T> {
|
||||||
|
|
||||||
return new Promise<T>((resolve, reject) => {
|
return new Promise<T>((resolve, reject) => {
|
||||||
|
|
||||||
@ -340,17 +340,18 @@ export class HttpHelper {
|
|||||||
if (showLog) {
|
if (showLog) {
|
||||||
LogHelper.debug(`postJson:${apiNo}\n`, JSON.stringify(params))
|
LogHelper.debug(`postJson:${apiNo}\n`, JSON.stringify(params))
|
||||||
}
|
}
|
||||||
|
// let data = HttpHelperX.getContent(params.data)
|
||||||
|
|
||||||
|
|
||||||
const formData: http.MultiFormData[] = params.data as http.MultiFormData[]
|
// const formData: http.MultiFormData[] = params.data as http.MultiFormData[]
|
||||||
httpRequest.request(HttpHelperX.getUrl(params.url, params.query), {
|
httpRequest.request(HttpHelperX.getUrl(params.url, params.query), {
|
||||||
method: http.RequestMethod.POST,
|
method: http.RequestMethod.POST,
|
||||||
connectTimeout: 20000,
|
connectTimeout: 20000,
|
||||||
readTimeout: 20000,
|
readTimeout: 20000,
|
||||||
header: header,
|
header: header,
|
||||||
// extraData: params.data,
|
extraData: params.data,
|
||||||
usingCache: false,
|
usingCache: false,
|
||||||
multiFormDataList: formData,
|
multiFormDataList: params.data,
|
||||||
})
|
})
|
||||||
.then((data: http.HttpResponse) => {
|
.then((data: http.HttpResponse) => {
|
||||||
if (showLog) {
|
if (showLog) {
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import { ToolsHelperForTS } from '../utils/ToolsHelperForTS';
|
import { ToolsHelperForTS } from '../utils/ToolsHelperForTS';
|
||||||
|
import { http } from '@kit.NetworkKit';
|
||||||
|
|
||||||
export interface HttpParamsGet {
|
export interface HttpParamsGet {
|
||||||
url: string
|
url: string
|
||||||
@ -12,6 +13,12 @@ export interface HttpParamsPost {
|
|||||||
query?: Record<string, string> | Object
|
query?: Record<string, string> | Object
|
||||||
headers?: Record<string, string | null | undefined>
|
headers?: Record<string, string | null | undefined>
|
||||||
}
|
}
|
||||||
|
export interface HttpParamsUpload {
|
||||||
|
url: string
|
||||||
|
data: http.MultiFormData[]
|
||||||
|
query?: Record<string, string> | Object
|
||||||
|
headers?: Record<string, string | null | undefined>
|
||||||
|
}
|
||||||
|
|
||||||
export interface HttpParamsForm {
|
export interface HttpParamsForm {
|
||||||
url: string
|
url: string
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import fileUri from '@ohos.file.fileuri';
|
import fileUri from '@ohos.file.fileuri';
|
||||||
import fs, { ListFileOptions, ReadOptions, ReadTextOptions, WriteOptions } from '@ohos.file.fs';
|
import fs from '@ohos.file.fs';
|
||||||
|
import fileIo, { ListFileOptions, ReadOptions, ReadTextOptions, WriteOptions } from '@ohos.file.fs';
|
||||||
import { BusinessError } from '@kit.BasicServicesKit';
|
import { BusinessError } from '@kit.BasicServicesKit';
|
||||||
import { StrHelper } from './StrHelper';
|
import { StrHelper } from './StrHelper';
|
||||||
import { hilog } from '@kit.PerformanceAnalysisKit';
|
import { hilog } from '@kit.PerformanceAnalysisKit';
|
||||||
@ -886,4 +887,18 @@ export class FileHelper {
|
|||||||
return (fileSize / (1024 * 1024 * 1024 * 1024)).toFixed(1) + "TB";
|
return (fileSize / (1024 * 1024 * 1024 * 1024)).toFixed(1) + "TB";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static copyFileToCacheDir(path: string):CacheFile {
|
||||||
|
const resFile = fileIo.openSync(path, fileIo.OpenMode.READ_ONLY)
|
||||||
|
let newPath = GlobalContext.getContext().cacheDir + "/" + resFile.name;
|
||||||
|
FileHelper.copyFileSync(resFile.fd, newPath)
|
||||||
|
return {
|
||||||
|
path: newPath,
|
||||||
|
name: resFile.name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export interface CacheFile{
|
||||||
|
path:string,
|
||||||
|
name:string
|
||||||
}
|
}
|
||||||
@ -66,7 +66,7 @@ export class PickerHelper {
|
|||||||
let photoPicker = new photoAccessHelper.PhotoViewPicker();
|
let photoPicker = new photoAccessHelper.PhotoViewPicker();
|
||||||
|
|
||||||
let photoSelectResult: photoAccessHelper.PhotoSelectResult = await photoPicker.select(options);
|
let photoSelectResult: photoAccessHelper.PhotoSelectResult = await photoPicker.select(options);
|
||||||
LogHelper.error(JSON.stringify(photoSelectResult))
|
// LogHelper.error(JSON.stringify(photoSelectResult))
|
||||||
if (photoSelectResult && photoSelectResult.photoUris && photoSelectResult.photoUris.length > 0) {
|
if (photoSelectResult && photoSelectResult.photoUris && photoSelectResult.photoUris.length > 0) {
|
||||||
return photoSelectResult.photoUris;
|
return photoSelectResult.photoUris;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
正在加载...
在新工单中引用
屏蔽一个用户