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?
How to use open file from device and upload using webview
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.
Here is a simple example of implementing WebChromeClient. You might have to implement the onShowFileChooser method to get file uploads work.
But i Need like this in HTML
<input type="file" name="Hello">
that not work to choose file in web view
Did you read the android docs in the given link? It must explain you why & how you need to implement the onShowFileChooser method.
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
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);
I haven’t tried personally but I guess iOS WebView works with file upload by default.