0.1.6 • Published 9 years ago

grunt-request-upload v0.1.6

Weekly downloads
1
License
-
Repository
github
Last release
9 years ago

grunt-request-upload NPM version

Upload files through POST/PUT HTTP request, using request!

Need Help?

It starts at the very beginning (including how to properly set-up your command-line on Windows and Mac OS X), and goes beyond the official Getting Started guide.

Getting Started

This plugin requires Grunt ~0.4.1

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-request-upload --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

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

The "request_upload" task

Overview

In your project's Gruntfile, add a section named request_upload to the data object passed into grunt.initConfig().

grunt.initConfig({

  request_upload: {
    your_target: {
      options: {
			method: 'POST',
			url: '',
			headers: {},
			data: {},			
			onProgress: function (percent, uploaded, total) {},
			onComplete: function (data) {},
			src: ''
		},
    },
  },

})

Options

options.method

Type: String Default value: 'POST' Default value: POST

The HTTP method to use to upload the file. Look in the API documentation you want to use, this is usually POST or PUT.

options.url

Type: String Default value: ''

This is the full URL to which you can upload a file. You can append some variables, like an API token.

options.data

Type: Object Default value: {}

Any form data fields to be sent in addition to the file upload

options.headers

Type: Object DefaultValue: {}

Headers to send along with your HTTP request. For example, a lot of API require the Authentication to be sent through the Headers.

options.onProgress

Type: Function DefaultValue: function(percent, uploaded, total) {}

Callback used to uploaded progress.

options.onComplete

Type: Function DefaultValue: function(data) {}

Callback used to process server's response. For example, when server returns id of uploaded file you need to process afterwards.

src

Type: String Default value: ''

The local path of the file you wish to upload, using the current working directory as a reference. You can upload only 1 file at a time.

0.1.6

9 years ago

0.1.5

9 years ago

0.1.4

9 years ago

0.1.3

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago