Search code examples
javascriptnode.jsamazon-web-servicesamazon-glacier

How to upload a file to amazon Glacier using Nodejs?


I found this example on the amazon aws docs.

var glacier = new AWS.Glacier(),
    vaultName = 'YOUR_VAULT_NAME',
    buffer = new Buffer(2.5 * 1024 * 1024); // 2.5MB buffer

var params = {vaultName: vaultName, body: buffer};
glacier.uploadArchive(params, function(err, data) {
  if (err) console.log("Error uploading archive!", err);
  else console.log("Archive ID", data.archiveId);
});

But I don't understand where my file goes, or how to send it to the glacier servers?


Solution

  • The file is stored in the vaultName, what ever value you provide there. The data.archiveId is the representation of the file. The body is the file it self.

    Here is a more general overview of Glacier

    Q: How is data within Amazon Glacier organized?

    Q: How do vaults work?

    Q: What is an archive?

    Cody Example: (As provided by hitautodestruct)

    var AWS = require('aws-sdk'),
        fs = require('fs'),
        glacier = new AWS.Glacier(),
        vaultName = 'YOUR_VAULT_NAME',
        // No more than 4GB otherwise use multipart upload
        file = fs.readFileSync('FILE-TO-UPLOAD.EXT');
    
    var params = {vaultName: vaultName, body: file};
    glacier.uploadArchive(params, function(err, data) {
        if (err) console.log("Error uploading archive!", err);
        else console.log("Archive ID", data.archiveId);
    });