New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problems saving in iOS Safari #12
Comments
Your Blob.js uses native blob constructor in Google Chrome, no? if (typeof Blob !== "function") |
I can verify that Filesaver does not work with 6.0.2. Safari does have a native Blob constructor. Both Chrome, as well as Firefox (opening in a new window as blob) work as advertised. |
Does anyone know of a workaround for this? |
This doesn't work on Safari. I suggest updating your REAME.md file so that people are aware of the regression. |
As I do not have a Mac, I really have no idea what exactly is causing the issue. It's up to you Mac users to fix this or donate a Mac/MacBook to me. |
Apparently just mentioning an issue in a commit closes the issue. I didn't mean to do that. |
Thanks for updating that. Mountain Lion does run in VirtualBox, if you're interested. http://www.macbreaker.com/2013/01/iatkos-ml2-mountain-lion-virtualbox.html |
I used to run OSX in VirtualBox and updates to VB or OSX broke compatibility every so often, so I'd rather not. The lack of hw acceleration is also pretty important. If you are not a developer you can pay someone who is and owns a Mac to fix this bug if donating a MacBook to me is too much for you. Frankly, seeing as FileSaver.js is a tool for developers most of you are probably developers and you should have no trouble debugging the issue at hand. |
I tried to reproduce and fix this issue but everything works fine for me in Safari 6 on OS X. |
@gawry @noway421 @ggozad @bendavis78 @Buttyx @marktheunissen Are you using Blob.js? Is |
@eligrey I'm using Safari 6, and doing testing on the demo page: http://eligrey.com/demos/FileSaver.js/ When clicking the 'Save' button, a new tab opens with the text in it and the url "data:text/plain..." in the address bar. |
@marktheunissen Thanks. Is |
Tell me if this fixes it for you: eligrey/Blob.js@6f36e8a |
I don't have an implementation of FileSaver anywhere to test this change, sorry. I'll let one of the others chime in, as we have moved to a different solution. Thanks for the help. |
An implementation of FileSaver for testing the change. |
I use FileSaver.js on a web application and I have support on mobile Safari and Safari on OS X desktop. As long as you include Blob.js as described in the README it works. Please note that Safari has support for Blob constructor but you cannot navigate to a Blob URI, therefore it has to fallback on a Data URI and the data will open in a new window. There is an issue in Blob.js when attempting to save large images, but that is unrelated to the bug being reported here. I think this reported bug should be closed unless someone has a specific demo showing the issue described. |
@missing Yes, it does open the data: URI in a new tab (as you can see in my screenshot above), but isn't the point of this library to make the browser save the file locally? The other problem is that you can't provide a default filename in this 'fallback' mode, so the user has to re-type it. |
@marktheunissen I have it working on Safari 6.0.5. So on this demo page it doesn't work? http://eligrey.com/demos/FileSaver.js/ |
Well, it doesn't behave as expected. It does provide a fallback where you get a data: url, and that does show the correct data in the tab. The problem is that it doesn't trigger the browser to automatically download the data, and when a user chooses "Save As" from the File menu, they have to re-type the name of the file that they typed on the first page. I'm not sure if this can be fixed by any library, it's probably a deficiency in the Safari browser. All I'm saying is that the user experience provided to Safari users is so different to other browsers, that this should be emphasized in the README so that implementers are aware of it. |
@marktheunissen Btw, you may be getting a cached version of the page as I have the site configured with pretty aggressive caching, so try clearing your cache before trying again.
Safari does not support saving filenames, only Chrome and Firefox (and possibly the new Opera) do at this time. |
@marktheunissen I understand the frustrations, I've been fighting with Safari and downloading data for a long time as well. The sad fact is that Safari hasn't implemented any of the other fallbacks that can be used here. This library first tries to use the W3C version of FileSaver and then goes to the anchor tag download attribute and finally to data URI. Mobile Safari on iOS handles data URIs in a special way however, if you mimetype it with text/csv for example when it pops you into the new window you'll get the iOS "Open In" bar which lets you open in other applications on your device that have registered as opening csv. In my opinion Safari hasn't implemented these other filesystem apis because they don't expose the filesystem to users on iOS. Maybe we can update the README to better reflect that. As of right now filenames work on the follow: Chrome, Firefox 20+ & Opera NEXT (new version of the Blink rendering engine). |
Sure thing. I'm not desperate for this bug to be solved in Filesaver, because we aren't using the library. I'm just helping out with testing. I guess the point is that most people would read the compatibility charts on the README file and expect that the user experience is the same across all browsers - that's the point of a shim like this. To have a very different user experience for one browser could be a deal breaker for a developer, and it sucks to have to go and test the library before discovering that on Safari it isn't consistent. |
@missing @marktheunissen I updated the readme to make it clear which browsers support saving filenames and which don't. As it stands, IE10, Firefox, Chrome, and Opera Next support it. |
@eligrey thanks, was just about to say IE10 too. |
@badray what about if you try the demo found here: http://eligrey.com/demos/FileSaver.js/ |
It still doesn't work on my tablet.
|
I can agree with @tayfunyasar, it's not working on iOS for me. I have submitted a bug report to Apple regarding the lack of download attribute for all the good it's likely to do. |
It's only fixed on Desktop Safari. iOS safari does still not (iOS 12.1) support the download attribute. |
So what's the recommended workaround for that? I'm facing same issue. I understand that i can either leave 'application/octet-stream' and it'll not work on IOS Safari or change it to proper content-type 'application/pdf' in my case but it'll open file in new tab with strange url 'blob:something'? Is there any other chance to force saving file in safari ios? |
@pawepaw I suppose that the opening in new tab is expected behavior for Safari <12 on iOS because the browsers do not have an access to file system. This gives the user a chance to save a file with an additional click to the cloud storage. |
I can save a file on iOS but not give it a name. @pawepaw See here: https://dotnetcarpenter.github.io/FileReader_Chrome/ |
This is still not working on iOS, with the exact same symptoms as described above. In my opinion this issue should not be closed |
Confirm for me also. Unfortunately the problem is still there |
Not working |
This is resolved in the new safari in iOS 13 with the introduction of three download manager. |
can this be reopened? this is still an existing issue |
I had the same issue with images download. iPhone, Safari. This helped: |
this code allowed you to DOWNLOAD file in your file system or OPEN it in safari tab? |
2020 and still the same problem? UNKNOW as name, and can't download octet-stream?? wow. |
@HansLanger Maintaining open source projects takes a lot of time, and sometimes people's priorities change, and life gets in the way. People create software and let you use it for free, so maybe don't be an ass in the face of free labor. Having a crappy attitude doesn't get problems solved any faster. |
@snipe: If you understand the problem you would understand that I was NOT complaining about FileSaver.js. I was complaining about Safari (which is not free). Sorry for the confusion. |
@HansLanger thanks for the clarification. (Safari is free, if you don't mind dropping $1k on an iPhone ;-) ) Did you try the solution @DevJhns mentioned? |
Yes, I tried everything on an Iphone. It just does not work. The Initial @gawry post describes everything perfectly, its a great information, but Apple has not solve the problem, and that is why my first comment. |
Looks like the "download" attribute was added in iOS 13 as of April 2020.
|
I tried it and the file was opened in current tab. it didn't download. |
Edit by @eligrey: Please tell Apple how this bug is affecting you in https://bugs.webkit.org/show_bug.cgi?id=102914 if you want this fixed.
Edit by @jimmywarting
The safari bug #102914 has been marked as fixed now
In the meantime, if you want to support Safari 7, you'll probably want to use Downloadify (uses Flash, not HTML5).
Issues we have had with Safari
This has been solved with Blob.js using BlobBuilder as fallback and then base64 data uri if that are not supported either
Has been covered by both FileSaver.js and blob.js
Blob.js overrule createObjectUrl with it's own base64 url constructor only if it's a "fake blob" (i.e not a File or Blob representation) it will use
window.URL
, fallback towindow.webkitURL
or use it's own base64 function to create those "fake blobs" data-uriplain/text
or a common image likeimage/png
.application/octet-stream
(wish is commonly used to force saving files from the server)If it's then it read the blob as base64 using FileReader to open a
data:attachment/file" + base64
url in order to save it.attachment/file
type directly and open it, then you will get errors like this:Failed to load resource: Frame load interrupted
it has to be base64 for some reason...This can easily be reproduced by doing:
If you replace
window.open
withlocation.href =
you will get theFailed to load resource: Frame load interrupted
and be unable to save the file that is not the case for all mimetype, mimetypes that Safari can display can be opened this wayA little side note here is that window.open only works on trusted events meaning:
onclick
event (more about isTrusted event here - almost pointless becuse browser support)I have also found out that the trusted event persist for 1000 ms, so you could do:
So the conclusion here about safari is
4.1 Create a base64 link with FileReader api
4.2 try to open a new tab using window.open + base64 url
4.3 if it was more then 1 sec before the user interaction happened it will use the current page instead
but that is likely going to fail because (see first example using location.href)
Failed to load resource: Frame load interrupted
This may still work if the mimetype is notapplication/octet-stream
and the saveAs was not called synchronousmsSaveAs()
data:attachment/file" + base64
ready and open that link using window.open() when the user interacts with the website (or at least to it under 1 second)The text was updated successfully, but these errors were encountered: