Downloading a pdf file using an android native browser fails - android

I am trying to download a pdf file using an ASP.Net MVC web application however have noticed that it always fails to download both 1) the file and 2) fail to open up the file within the browser.
Note: The link does not point to a URL + filename with a .pdf extension...it directs to a controller/action that should return the pdf.
All the correct content types/MIME types have been setup correctly:
pdf: application/PDF
ppt: application/vnd.openxmlformats-officedocument.presentationml.presentation
xlsx: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
...just not sure why it doesn't work.
Can anyone shed any light on this please.
What I would like to achieve is either viewing the file within the browser or downloading the file to the phone to view.
Note: Seems to work perfectly well on ios mobile safari browser, and all desktop browsers!
Note 2: the actual error message in the notification area in Android is:
< Untitled >
Download unsuccessful.

Related

load local file in webview ios using http protocol. (Create Webview server in android and iOS)

Is there any way to create the server in android and iOS to run a web-view? I want to run a local HTML file in a web-view with a local-host URL.
I have already searched for this on the following links but could not find any solution.
GCDWebServer
local-http-server-for-ios
Supercharging the Android WebView
Hereby i am sharing the actual scenario :
1) Download ".zip" file from server and save it on application library directory for offline use.
2) ".zip" file contents html and javascript files. It works when the HTML page is simple. But if the HTML references something else, i.e. a JavaScript file also in the library directory (with an absolute path like ), it will fail to load.
3) I need to setup local server in my device, On application launch local server starts and upload the application library directory on local server and then load the content using local host. See below example
Using Library directory path
file:////Users/prince/Library/Developer/CoreSimulator/Devices/75EF3DD7-DFD1-4EDB-9A6B-9FBA60F4D98C/data/Containers/Data/Application/32F774B2-E811-4281-A37A-DC8A5183B7C8/Library/Application%20Support/adededfe6c1c7bd8b5d5adb19861b9e0/Responses/36b8f6a8d6f58d58f117856dc80b0d37/abc.html
Using localhost path
http://localhost:8080/Application%20Support/adededfe6c1c7bd8b5d5adb19861b9e0/Responses/36b8f6a8d6f58d58f117856dc80b0d37/abc.html
Does anyone know why this happens, and how to resolve the issue?

Download video from s3, works in Android and Desktop, but not in iOS

My website creates "presigned-url" to download files from Amazon S3.
In Desktop and Android this URL starts download perfectly using Chrome or other browser.
https://s3.sa-east-1.amazonaws.com/videos.cinemedsite.com.br/888888/888888_00000000000_20180808_235040.mp4?AWSAccessKeyId=AKIAJQCURENNFPNNGK6A&Expires=1609383840&Signature=4lYLxgkAIt3xMer%2FPcL%2FAepwbkY%3D
But with this same URL on iOS (iPad and iPhone tested), the video just plays in any browser and there's no way to download.
I've tried to download directly from aws console too, no success.
Metadata is already configured as :
content-disposition: attachment;filename=lixo.mp4
content-type: video/mp4 (already tried application/octet-stream also).
Any ideas ?
Thanks in advance!
Marcello
On iOS there is not a user accesable file systems with default download 'folder' as you have on a PC or MAC - i.e. you can't just click a link in the browser and have the file download to it.
With Apps like dropbox you van open a PDF file, for example, in your browser and then click the Share button and choose Dropbox to download to your device. 'Documents', another app available on the appstore, has a built in browser so is worth looking at also.
You can create your own application which will accept a URL, download it and then provide a list or directory of downloaded files. These files will only be visible by the app unless you add some functionality to save them to, for example, the gallery.
There is an AWS SDK available on Github which would be a good place to start if you are using your own app: https://github.com/awslabs/aws-sdk-ios-samples

Android URL Scheme To Open File From Browser Link?

On Android (8.0), I'm trying to create a local html file that includes links to some local files that can't be viewed directly by Chrome, like <a href="relative_path_to_file/file.docx">. In a normal web browser (i.e. on a PC), I can click the link and it will open the file in its default viewer. On Android, if I open one of the local html files in Chrome and click one of those links, it directs me to content://nextapp.fx.FileProvider/path_to_file/file.docx, showing "Your file was not found." I do have an appropriate app installed to view the file (I can open it via a file explorer app). I would like to understand how I can structure the URLs such that docs of various types (i.e. docx, xlsx, pdf, etc) can be accessed via the links that refer to them - clicking the link should offer to open the file, as it does when accessing the file from a file manager.
I tried rewriting the links to an absolute path, i.e. "/storage/emulated/0/path/file.docx." The result is the same.
I tried rewriting the links to "file:///storage/emulated/0/path/file.docx." Chrome just redirects to about:blank.
I tried opening the html doc with "HTML Viewer" rather than Chrome. The behavior is more or less the same (in the first case it redirects to about:blank, in the second it says "No app available to open link.")
How can I structure the link so it can be clicked & open the referred-to file in appropriate viewer?
Finally figured it out. A working link to open the local file in its default viewer looks like:
"intent:///abs/path/to/file.docx#Intent;scheme=file;action=android.intent.action.VIEW;end;"
...With one important caveat: it breaks if there are any "dots" in the path (i.e. I had the files in a .hiddenFolder, which apparently causes Chrome to be unable to figure out the intent link).
Reference: https://developer.chrome.com/multidevice/android/intents

Content-disposition doesn't work on Android Chrome

I'm trying to force a pdf file to download and save rather than be displayed in the browser.
I've set both Content-Type ("application/octet-stream") and Content-Disposition ("attachment"), but on the Android version of Chrome, it still opens in the browser. On desktop (Windows) Chrome it correctly switches to downloading the file with just the content-disposition applied.
Is there some other setting that I'm missing that can be included in my server side code to set the proper behavior? I'm needing the additional features of full PDF software rather than the simple built in viewer.
I was only able to open PDF in browser when I opened a url that is itself has extention .pdf.
When dynamically generate a PDF using a .aspx file it never opened the PDF in browser on Android Chrome or any other Android browser. (PC, iOS did work however.)
The best solution for Android Chrome was to let it download the PDF and automatically open the PDF with the default PDF viewer app.
I used the following settings:
Content-Type: application/pdf
Content-Disposition: attachment; filename = "some document name.pdf"

Desktop web site can't open pdf file on mobile devices - how to

VS2010 VB.NET ASP.NET
I have a simple site where the user clicks a button and a pdf file is displayed in a new broswer window.
To do the this a button launches a new browser window with the following code in the page load event:
Response.Clear()
Response.ClearContent()
Response.ClearHeaders()
Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1))
Response.Buffer = True
Response.ContentType = "application/pdf"
'Response.ContentType = "text/plain"
If Download_Flag Then
'force SaveAs (this is the download option)
Response.AppendHeader("Content-Disposition", "attachment; filename=" & "myfile" & ".pdf")
Else
'open in borwser
Response.AddHeader("Content-Disposition", "inline")
End If
Response.OutputStream.Write(PdfBuffer, 0, PdfBuffer.Length)
Response.OutputStream.Flush()
Response.OutputStream.Close()
Response.End()
PDFBuffer is a byte array containing the pdf document
This code displays the pdf file in the browser (ie, chrome, mozilla, safari?) using whatever pdf plugin is installed.
if download_flag is true then the pdf is not opened in the viewer but instead browser prompts with the save file dialog
As I said, this code works in desktop borwsers, but it does not work on an ipad or an android phone, and propably other devices as well.
The site is not mobile aware, but if need be it could, I suppose.
I know that apple does not allow downloads, and android may not be able to open open an additional window, so how can I open a pdf file on a button click on these devices? I know he ipad and the android can both open pdf files, I've done it on other sites.
My solution was to open the pdf file in the same window as the site. On android this causes a file download to which the user can go to the downloads folder and view the pdf. On ipad this opens the default pdf viewer. If ipad user download the adobe pdf viewer they can switch over to the adobe reader from the default ipad reader; the adobe reader allows print and email of document. On desktop browser this solution shows the pdf in the same window and user can use the browser's back button to get back to the site when they are done with the pdf. A more robust solution would be to detect the client and act appropriately, but with this common implementation is workable.
Speaking for Android, Content-Disposition is tricky to get working properly:
Avoiding content type issues when downloading a file via browser on Android
http://www.digiblog.de/2011/04/android-and-the-download-file-headers/
http://winzter143.blogspot.com/2012/03/android-handling-of-content-disposition.html

Categories

Resources