1/* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { webview } from '@kit.ArkWeb'; 17import { BusinessError } from '@kit.BasicServicesKit'; 18import { picker } from '@kit.CoreFileKit'; 19 20@Entry 21@Component 22struct WebComponent { 23 controller: webview.WebviewController = new webview.WebviewController(); 24 25 build() { 26 Column() { 27 Web({ src: $rawfile('local.html'), controller: this.controller }) 28 .onShowFileSelector((event) => { 29 console.log('MyFileUploader onShowFileSelector invoked'); 30 const documentSelectOptions = new picker.DocumentSelectOptions(); 31 let uri: string | null = null; 32 const documentViewPicker = new picker.DocumentViewPicker(); 33 documentViewPicker.select(documentSelectOptions).then((documentSelectResult) => { 34 uri = documentSelectResult[0]; 35 console.info('documentViewPicker.select to file succeed and uri is:' + uri); 36 if (event) { 37 event.result.handleFileList([uri]); 38 } 39 }).catch((err: BusinessError) => { 40 console.error(`Invoke documentViewPicker.select failed, code is ${err.code}, message is ${err.message}`); 41 }) 42 return true; 43 }) 44 } 45 } 46} 47