Andrew (Digitwell) Well-Known Member Licensed User Longtime User Aug 16, 2021 #1 I want the user to be able to select a PDF file from their local storage, display a preview of the PDF file and then upload the file to a remote server. I have all of this working fine with B4i using the code from https://www.b4x.com/android/forum/threads/b4x-texteditor-save-and-load-external-files.132731/ and multipart post. However, I have run into problems with B4A. I have modified (slightly) the code from this tutorial to demonstrate the first part problem I am having: I can select a file, however, I cannot then display it in a webview nor can I upload it using multipart post. Strangely, the ReadString function works fine. I am using LoadUrl on the Webview to display the PDF. B4X: Copy WebView1.loadurl(xui.FileUri(Result.dir,Result.filename)) ' WebView1.loadurl(File.combine(Result.dir,Result.filename)) Page Finished show that the webview thinks it has loaded the file. B4X: Copy private Sub webview1_PageFinished (Url As String) toast.show($"Finished loading ${Url}"$) Log($"Finished loading ${Url}"$) End Sub The commented out line just gives a file not found error. Spoiler: Log output Finished loading file://contentdir/content%3A%2F%2Fcom.android.providers.downloads.documents%2Fdocument%2F3197 Any ideas what I am doing wrong? FYI I am testing on a Samsung Galaxy Tab A Attachments TextEditorwebview.zip TextEditorwebview.zip 184.4 KB · Views: 511
I want the user to be able to select a PDF file from their local storage, display a preview of the PDF file and then upload the file to a remote server. I have all of this working fine with B4i using the code from https://www.b4x.com/android/forum/threads/b4x-texteditor-save-and-load-external-files.132731/ and multipart post. However, I have run into problems with B4A. I have modified (slightly) the code from this tutorial to demonstrate the first part problem I am having: I can select a file, however, I cannot then display it in a webview nor can I upload it using multipart post. Strangely, the ReadString function works fine. I am using LoadUrl on the Webview to display the PDF. B4X: Copy WebView1.loadurl(xui.FileUri(Result.dir,Result.filename)) ' WebView1.loadurl(File.combine(Result.dir,Result.filename)) Page Finished show that the webview thinks it has loaded the file. B4X: Copy private Sub webview1_PageFinished (Url As String) toast.show($"Finished loading ${Url}"$) Log($"Finished loading ${Url}"$) End Sub The commented out line just gives a file not found error. Spoiler: Log output Finished loading file://contentdir/content%3A%2F%2Fcom.android.providers.downloads.documents%2Fdocument%2F3197 Any ideas what I am doing wrong? FYI I am testing on a Samsung Galaxy Tab A
Erel B4X founder Staff member Licensed User Longtime User Aug 16, 2021 #2 1. Android WebView doesn't support PDF documents. 2. Don't use FileUri with this url. Result.filename is the url. Upvote 0
1. Android WebView doesn't support PDF documents. 2. Don't use FileUri with this url. Result.filename is the url.
Andrew (Digitwell) Well-Known Member Licensed User Longtime User Aug 16, 2021 #3 Erel said: 1. Android WebView doesn't support PDF documents. 2. Don't use FileUri with this url. Result.filename is the url. Click to expand... Ah, that would explain it. I try give PDFium to view the PDF instead, https://www.b4x.com/android/forum/threads/pdfium-pdfview2.102756/#post-644710, as I would prefer to have the PDF in a view rather than call an intent which would be full screen. So using Multipart post to upload the file to a server, is it ? B4X: Copy Dim mp As MultipartFileData mp.Initialize mp.Dir = result.dir mp.FileName = result.filename Upvote 0
Erel said: 1. Android WebView doesn't support PDF documents. 2. Don't use FileUri with this url. Result.filename is the url. Click to expand... Ah, that would explain it. I try give PDFium to view the PDF instead, https://www.b4x.com/android/forum/threads/pdfium-pdfview2.102756/#post-644710, as I would prefer to have the PDF in a view rather than call an intent which would be full screen. So using Multipart post to upload the file to a server, is it ? B4X: Copy Dim mp As MultipartFileData mp.Initialize mp.Dir = result.dir mp.FileName = result.filename
Erel B4X founder Staff member Licensed User Longtime User Aug 16, 2021 #4 Andrew (Digitwell) said: So using Multipart post to upload the file to a server, is it ? Click to expand... Yes Upvote 0
Andrew (Digitwell) said: So using Multipart post to upload the file to a server, is it ? Click to expand... Yes