Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Upload file to Mapbox Tileset (node.js)
Uploads a tileset (tested with to Mapbox S3 (required),
then triggers an API request to Mapbox to create/update the tileset
node uploadToMapBoxTileset.js [path/to/] [tilesetId] [Tileset Title]
Pro tip: Don't foget to change {username} and {access_token} and/or hardcode the process.argv[] values.
var AWS = require('aws-sdk'),
request = require('request'),
s3 = require('s3');
request("{username}/credentials?access_token={access_token}", function(err, res, body) {
// For dev purposes only
var keys = JSON.parse(body);
keys.region = "us-east-1";
var client = s3.createClient({
s3Options: keys
var params = {
localFile: process.argv[2],
s3Params: {
Bucket: keys.bucket,
Key: keys.key
var uploader = client.uploadFile(params);
uploader.on('error', function(err) {
console.error("unable to upload:", err.stack);
uploader.on('end', function() {
console.log("Finished uploading to Mapbox S3");
//sync tileset
var options = {
uri: "{username}?access_token={access_token}",
method: 'POST',
json: {
tileset: process.argv[3],
url: keys.url,
name: process.argv[4]
};, function(err,httpResponse,body){
console.log("Mapbox Tile Sync - "+httpResponse.statusMessage+" ("+httpResponse.statusCode +")");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.