Sample code for uploading files directly with XHR/CORS
JavaScript HTML
Latest commit 37c9784 Nov 3, 2015 @sqrrrl sqrrrl Merge pull request #3 from sauvainr/master
Handle upload errors
Failed to load latest commit information.
LICENSE Initial commit Sep 18, 2013 Update Sep 18, 2013
index.html Fix missed renamed option Sep 18, 2013
upload.js Handle upload errors Sep 1, 2015


Sample code for uploading files directly with vanilla Javascript (XHR/CORS). Try the live version and drag & drop files to upload them to Google Drive.

This sample has only been tested with Chrome. Other browsers may or may not work.


If you'd like to use the code in your own project, copy upload.js and include it.

<script src="/path/to/upload.js"></script>

When uploading a file, create a new MediaUploader initialized with a Blob or File and access token. Then call upload() to start the upload process.

var uploader = new MediaUploader({
  file: content,
  token: accessToken,

Your access token need to be authorized for any of the Drive scopes that permit writes (drive, drive.file, or drive.appdata.) You can go through one of the OAuth 2.0 flows to retrieve one or use Google+ Sign-In button.

See upload.js for additional parameters you can include when initializing the uploader, including callbacks for success & failure events.