How to use open file from device and upload using webview


#1

Hi guys,
i am trying to get a file say mp3 to upload using socket.io-stream in a webview, but it seem not to open the file manager to sellect a file from device. but if i use it in a web browser it works , How do i do it from webview?


#2

You will have to handle that yourself by implementing your own WebViewClient, you may get enough examples for Android which you may convert to TypeScript / JavaScript.


#3

can I have links to examples
i need it please


#4

Here is a simple example of implementing WebChromeClient. You might have to implement the onShowFileChooser method to get file uploads work.


#5

Thanks For Your Response


#6

But i Need like this in HTML

<input type="file" name="Hello">

that not work to choose file in web view


#7

Did you read the android docs in the given link? It must explain you why & how you need to implement the onShowFileChooser method.


#8

Sorry Thanks For support I didn’t Read it Carefully


#9

I have Problem in implementing

`onShowFileChooser(webView,filePathCallback,fileChooserParams) {

        // this.filepathCallback(filePathCallback);
         filePathCallback.onReceiveValue();
        return true;
    }

    filepathCallback(filePathCallback)
    {
        let context = imagepicker.create({
            mode: "single",
            mediaType: imagepicker.ImagePickerMediaType.Any
        });
        return this.startSelection(context,filePathCallback);
    }

    private startSelection(context,filePathCallback) {
    let abc = context.authorize().then(() => {
                                    return context.present();
                                  })
            .then((selection) => {
                selection.forEach((selected) => {
                    let path = selected.android;
                    let file = fs.File.fromPath(path);
                    this.file_path = file.path;
                    filePathCallback = file.path;
                    return this.file_path;
                });
            }).catch(function (e) {
                console.log(e);
            });
    }

How Can i set file path or file to return


#10

I have used imagepicker plugin to choose file in android


#11

You will have to pass the selected file path to onReceiveValue method.


#12

Thank you For Your Help

Two major things has been done one is File Upload and Second Cookie Setting

as i Have read that ios support file upload so is there any need to implement it.

this.file_path = "file://" + this.file_path;
let results = Array.create(android.net.Uri, 1);
results[0] = android.net.Uri.parse(this.file_path);
filePathCallback.onReceiveValue(results);

#13

I haven’t tried personally but I guess iOS WebView works with file upload by default.