Grunt HTTP Upload

0.3.2 · maintenance · verified Wed Apr 22

grunt-http-upload is a Grunt plugin designed for automating file uploads via POST or PUT HTTP requests directly within a Grunt build process. It allows developers to integrate file delivery to RESTful APIs or content management systems as part of their CI/CD or deployment workflows. The plugin currently sits at version 0.3.2, with its last update in 2016 primarily focused on replacing the deprecated `Restler` library with `Request` to ensure compatibility with newer Node.js versions (>=6.0.0). While Grunt itself has a less active development cadence compared to newer build tools, this plugin remains functional for existing Grunt-based projects needing straightforward HTTP file uploads. Its key differentiator is its deep integration into the Grunt ecosystem, simplifying what would otherwise require custom scripting or external `curl` commands.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to configure and run the `http_upload` Grunt task to upload a file to a specified API endpoint, including options for URL, method, headers, and data fields.

module.exports = function(grunt) {
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    http_upload: {
      your_target: {
        options: {
          url: 'https://api.example.com/upload?token=<%= pkg.apiKey %>', // Use template for API key or env var
          method: 'POST',
          rejectUnauthorized: true, // Typically set to true for production
          headers: {
            'Authorization': 'Bearer <%= process.env.UPLOAD_TOKEN ?? "" %>'
          },
          data: {
            version: '<%= pkg.version %>',
            environment: 'production'
          },
          onComplete: function(response) {
            console.log('Upload complete. Server response:', response);
          }
        },
        src: 'dist/<%= pkg.name %>-<%= pkg.version %>.zip', // Source file to upload
        dest: 'file' // Field name for the uploaded file on the API side
      },
    },
  });

  grunt.loadNpmTasks('grunt-http-upload');

  // A default task to run the upload
  grunt.registerTask('deploy', ['http_upload:your_target']);

  // Example of a minimal package.json excerpt for the quickstart to be runnable:
  // { "name": "my-project", "version": "1.0.0", "apiKey": "YOUR_API_KEY" }
  // Remember to set UPLOAD_TOKEN environment variable or replace with actual token.
};

view raw JSON →