Google Docs Viewer with Amazon S3 Private Documents and Presigned URLs

coding software

So recently one of our developers discovered an awesome service that Google Docs provides called the Google Docs Viewer. It's super powerful and super easy to use. Basically, it's a service that allows you to pass a URL of a document to this service, and it will render a preview of the document that's usable in the DOM. This is amazing for providing previews of common documents like PDF, DOCs and more. We saw Trello use it so we thought it's gotta be a good solution.

Here's an example:

<iframe src=''></iframe>

You could slap that iFrame into your HTML and boom, you have a preview of a PDF document embedded in your website.

However, the app that we were building was using private, protected documents hosted on Amazon S3. So to pass a URL to the Google Docs Viewer, we had to get a presigned URL. So it would look something like this:

<iframe src=''></iframe>

As soon as we did this, we kept getting a "No Preview Available" error from Google Docs. After trying lots of solutions, it turns out the error had to do with the fact that we were passing a URL with Query String params as a query string param to another URL. That is, the Amazon S3 Presigned URL contains query string parameters, so it contains a "?" and "&" which confuses the outer URL.

So long story short, you have to Encode the S3 Presigned URL before passing it to the Google Doc Viewer.

If you're using Presigned URLs, my guess is that you're dynamically setting the URL. We do it with Javascript, so our code looks something like this:

var encodedUrl = encodeURIComponent(amazon_presigned_url);
var iFrameUrl = '' + encodedUrl + '&embedded=true';

We did run into an issue where we tried encodeURI instead of encodeURIComponent, but that was just our misunderstanding of those methods. If you're doing server-side encoding, make sure you're it's correctly removing "/", "?", and "&".

Alright, that's it for now. Hopefully this helps out some peeps.

Casey Li
CEO & Founder, BiteSite

React Native fetch only working with localhost and NOT IP addresses

coding software

Alright, this will be a quick one. So I was using 'fetch' to make a web request in my React Native app. My server was a Rails app. When I used 'localhost' in my request, the request would work perfectly, but if I used my IP address, the network request would fail.

fetch('localhost:3000')   /* this would work fine */
fetch('')    /* this would not work */

I double-checked to make sure my Rails server wasn't the issue and ensured it was bound to

rails s -b

So that was good. In fact, if I went into my iOS simulator and launched Safari, Safari could hit the localhost:3000 and IP Address:3000 no problem. So my iOS Simulator could hit my Rails app, but not my React Native app using the IP Address. Again, everything worked fine using localhost.

Turns out this is an iOS 9 issue where by default, HTTP requests are blocked (vs HTTPS requests). So to allow this you need to enable "Allow Arbitrary Loads" in your Info.plist in your XCode project.

For more details, check out this link

Casey Li
CEO & Founder, BiteSite

Creating 3D line objects using After Effects and C4D lite

film after effects motion graphics

Creating true 3D objects inside After Effects became possible with the addition of the Cinema 4D Lite application. C4D Lite was added to the 2014.1 release of After Effects CC. With C4D lite being shipped along with AE, users who have never even considered working with a 3D program like C4D now have access to it. It's right there at your fingertips... you gotta check it out!

In one of BiteSite's recent projects, I was able to take advantage of the 3D capabilities C4D offers. In this post we'll focus on a unique look you can create inside AE with 3D objects from C4D. It's so simple and quick you may have already thought this up on your own! It's something that not only adds a new look, but may also add more functionality to your project. Check it out...

Apply these 2 effects (in this order) to the 3D layer inside AE:

  1. Find Edges --> for the look we're after, click the 'invert' option
  2. Unmult --> this is not an effect that comes with AE. It's free though and you can download it here:

What do these effects do?

  1. Find Edges --> It finds the edges... ;) Perhaps a little self-explanatory, perhaps not! Find edges looks at any shape, image, or object (whatever type of layer you apply it to) and recognizes all of the 'edges' in that layer. Edges are any part of the image where there is a significant transition. It then turns to white everything in the layer that is not an 'edge'. Checking off 'invert' on the effect turns everything to black rather than white.
  2. Unmult --> makes 100% black areas of an image completely transparent, and leaves 100% white areas completely opaque. Everything in between adjusts accordingly. Unmult is effectively creating an alpha channel for an image that doesn't actually have one. Awesome!

Apply these two effects, and you now have a 3D line object! You can choose to have it transparent or opaque (just toggle on/off the unmult effect).

No effects added:

Find Edges:

Find edges + Unmult:

This look can be great if, -- you want that sketched art look (try adding the 'turbulent displace' effect to further this look), -- you just want fresh and simple lines instead of heavy 3D objects, -- or even just for the added functionality you get by having your 3D objects transparent!

As well, try duplicating your 3D object layer and keep it placed directly above it's duplicate in the composition panel. Have one layer with the effects applied and one without!

Try it out! If you're reading this and you use this method, leave a comment below with a link to your video We'd love to see your work. Cheers :)


Tim Clark
Filmmaker, BiteSite

Careful with Bang Operators in your Rails Models and ActiveRecord Callbacks (Frozen String error)

coding software ruby on rails

Alright here's a weird one that would have been easy to solve if I thought more about how Ruby works (and how it's not like Java:)).

So here was the issue, we were looping through a set of keys on a hash. Now, you should know that the keys on this hash were strings. So we had something like this

my_hash = {"color" => "blue", "size" => "medium" }

Now, on top of that we had a model that we'll call Person that had a "name" attribute and looked something like this:

class Person < ActiveRecord::Base
  before_validation upcase_name

    def upcase_name

Ok, for those who don't know, the bang version of upcase, upcase!, uppercases a string in place - it modifies the actual string itself.

So here is the setup, we were looping through keys of the hash:

my_hash.keys.each do |name|

Now, first thing to know is that you CAN'T modify a key in a hash. Anytime you try to modify the keys of a hash, you get an error. So something like this would produce an error:

my_hash.keys.each do |name|
  name.upcase!    # produces frozen string error

That all makes sense.

What we were surprised to see was that the following code also produces a similar error:

my_hash.keys.each do |name|
  Person.create(name: name)    # produces frozen string error

What's going on here? Well it turns out that the "before_validation" callback tries to upcase the name. But unlike languages like Java, the string that is passed in is the exact same object that exists in the "my_hash.keys" array. (I'm purposely avoiding by-value and by-reference wording here, because I feel it can lead to confusion)

So the hash holds a frozen lock on that string, and then when that string gets passed into the Person constructor, and the callback tries to modify it - you get the frozen string error.

How do you fix it? Change your callback:

class Person < ActiveRecord::Base
  before_validation upcase_name

    def upcase_name
      name = name.upcase

This version doesn't modify the original string but rather produces a new string.

Special thanks to d3chapma for helping me figure this one out. Check out his Gist here for more info.

Hope this helps out some peeps!

Casey Li
CEO & Founder, BiteSite

React Native Env 'cannot read property get of undefined'

coding react native software

Alright, in my continuing effort to use React Native, I keep running into little issues with all the libraries I use. Usually it's due to a setup issue and my lack of understanding of the true under-workings of what I'm doing seems to lead to these issues.

Today, it's with react-native-env. When setting this library up, I kept running into an issue that would say 'cannot read property get of undefined' or 'cannot read property getAll of undefined'.

When I started debugging, it seemed the EnvironmentManager object was present, so what was the issue.

If you look at your


you'll see that the get and getAll methods are delegating it to some native code:


So it's really just an issue of not reading the instructions properly. You need to add the RNEnvironmentManagerIOS.h and .m files to your project.

The only thing I found a little misleading is you shouldn't add the folder - rather add the individual files.

So in XCode, (I have a group called 'Libraries' under my project, but I think you can add it anywhere), right-click and "Add files to ", and make sure to select the individual RNEnvironmentManagerIOS.m and RNEnvironmentManagerIOS.h files.

Hope that helps out some peeps!

Casey Li
CEO & Founder, BiteSite