UPDATE 2016-11-16 9:53am EST
It appears many people are still seeing 204 responses even though Google has claimed to have "fixed" the problem. When I myself tested the loading of a document 50 times, 3 of those times Google returned a 204 response.
Please visit this URL and post a comment of your unhappiness so that we can finally get Google to address and fix the issue once and for all: https://productforums.google.com/forum/?utm_medium=email&utm_source=footer#!msg/docs/hmj39HMDP1M/SR2UdRUdAQAJ
UPDATE 2016-11-04 6:01pm EST
It looks like the service is up and working again! Thanks to Google Docs for addressing the issue and answering my tweets. Hope it's working for all of you too.
UPDATE 2016-11-04 3:33pm EST
There was an update published to https://productforums.google.com/forum/#!msg/docs/hmj39HMDP1M/X6a8xJwLBQAJ which seems to indicate support for the service might be returning and/or there was an issue on their end which caused unintended results. Stay tuned. See comment immediately below:
Original Post on Stack Overflow Starts Here
Our web software used and relied on the Google Docs viewer service to embed documents into our website (via iframe) and to give our customers the ability to view docs without having to open separate applications (via visiting the URL). This functionality was provided by Google for quite some time and had worked perfectly!
Example viewer URL:
https://docs.google.com/viewer?url=http://www.pdf995.com/samples/pdf.pdf
We began to notice, however, that files we were trying to load would only load very rarely. We initially thought there was an issue with their servers so began investigating the header responses we were getting. Particularly, we noted that nearly every request made was returning a 204 No Content response. Very occasionally we got a 200 response.
Here's an example of one of the 204 responses we got:
Here's an example of one of the 200 responses we got (very rare):
After that I searched Google for 204 issues associated with the Google viewer service. I ended up on this page https://productforums.google.com/forum/#!msg/docs/hmj39HMDP1M/X6a8xJwLBQAJ which seems to indicate that Google has suddenly and abruptly discontinued the service. Here's a screenshot of that discussion (as of the time of this post).
Given the fact that a Google "expert" replied to the person's similar inquiry; it seems that they've officially and totally abandoned support for the viewer service.
My questions are the following:
Does anyone else know for certain whether Google officially ended its support of the Google viewer service?
Does anyone know of an updated similar Google product/service (perhaps Google Drive?) that allows a person to do the exact same thing as the viewer service referenced above? Ideally, I'd like a simple URL where I can reference an external document that doesn't have to exist on a Google server but can still reside on my server.
What are some other comparable and free services you can suggest to allow me to embed documents such as Word docs, Excel docs, PowerPoint docs, and PDFs into a website that allows the user to view the documents within the browser without having to have those applications actually installed on their system.
As a final note, I just want to say that for all the good Google does it's incredibly infuriating, frustrating, and annoying that they can offer a service that people rely on for a long time and suddenly pull the plug on it. I'm sure there are many others besides just myself that will never bother voicing concerns over that type of decision. Google corrected the issue and is still good in my book :-)
Thanks ahead of time for your answers!
I run a service that also relies on embedding the Google Doc Viewer and I have also encountered this issue. I could not find any other comparable service (free or otherwise).
I have come up with a 'hack' that can help you get away with using the Google Doc Viewer. It does require JQuery though. What I do is keep refreshing the iframe every 2 seconds until it finally loads correctly. I also cover the iframe with a loading gif to hide the constant refreshing. My code:
<style>
.holds-the-iframe {
background:url(/img/loading.gif) center center no-repeat;
}
</style>
<div class="holds-the-iframe">
<iframe id="iframeID" name="iframeID" src="https://docs.google.com/viewerng/viewer?url=www.example.com&embedded=true"></iframe>
</div>
<script>
function reloadIFrame() {
document.getElementById("ifm").src=document.getElementById("iframeID").src;
}
timerId = setInterval("reloadIFrame();", 2000);
$( document ).ready(function() {
$('#iframeID').on('load', function() {
clearInterval(timerId);
console.log("Finally Loaded");
});
});
</script>
I was using the Google Viewer as a copy viewer for our internal management system, we generally only upload PDF's and image files, so as a all-in-one solution is was brilliant, worked across the board (mobile, desktop etc). However with it becoming increasingly unreliable, I got creative.
My solution was to generate and save a JPG version of the PDF using imagick if it was viewed after being uploaded. Rather than batching all of the uploaded PDFs, they are only converted when they are accessed.
My reasoning for that is:
- I have a very small user pool so file types are easily managed
- The likelihood of every PDF needing to be viewed again after upload is almost nil, so it's only created when needed for reporting purposes.
- I need a reliable way of viewing the file via mobile devices. iOS and Android do not play well with in browser PDF viewers and everyone knows how much hassle PDF's are on an iOS device (iBooks anyone?)
Once the file has been viewed and a jpg version of the pdf created, it is used in place of the PDF whenever it is viewed by a user. Not pretty but certainly works, I admit there is an element of doubling up however I do not have any storage limitations. The original file is also not modified in anyway so it serves as a tertiary remote backup too. This is not by design, but a happy coincidence.
Feel free to use the code below if it's useful to you. There are probably more elegant ways to do this, but for my purposes and users it's fine.
$_thumbnail = 'files/thumbnails/'.$_section.'/'.$_fileName.'.jpg';
if (!file_exists($_thumbnail)) {
$_file = 'files/'.$_section.'/'.$_fileName;
$imagePreview = new imagick();
$imagePreview->setResolution(300, 300);
$imagePreview->readimage($_file);
$imagePreview->setImageFormat( "jpg" );
$imagePreview->writeImage('files/thumbnails/'.$_section.'/'.$_fileName.'.jpg');
echo '<img src="/files/thumbnails/'.$_section.'/'.$_fileName.'.jpg" width="100%"/>';
} else {
echo '<img src="/files/thumbnails/'.$_section.'/'.$_fileName.'.jpg" width="100%"/>';
}
A simple solution/hack with Reactjs, though can be easily implemented to any other library/vanilla.
Used with a basic concept : tries to load - if onload accomplish, clear interval, otherwise try to load again every 3 sec. works perfectly
(I've edited my own code it so it will contain minimum code, so not tested)
var React = require('react');
export default class IframeGoogleDocs extends React.Component {
constructor(props) {
super();
this.bindActions();
}
bindActions() {
this.updateIframeSrc = this.updateIframeSrc.bind(this);
this.iframeLoaded = this.iframeLoaded.bind(this);
}
iframeLoaded() {
clearInterval(this.iframeTimeoutId);
}
getIframeLink() {
return `https://docs.google.com/gview?url=${this.props.url}`; // no need for this if thats not dynamic
}
updateIframeSrc() {
this.refs.iframe.src = this.getIframeLink();
}
componentDidMount() {
this.iframeTimeoutId = setInterval(
this.updateIframeSrc, 1000 * 3
);
}
render() {
return (
<iframe onLoad={this.iframeLoaded} onError={this.updateIframeSrc} ref="iframe" src={this.getIframeLink()}></iframe>
);
}
}