Automattic/wpcom.js — pull request #56 by retrofox (2014-10-20 23:48:01+00:00)
Title: Improve/media

### Add `query` optional parameter in all media methods

ie: `media#addUrls([query,] body, fn)`

It necessary allow pass `query` parameter in all methods. *First* because all REST-API endpoints allow them.
Look in [site/new](https://developer.wordpress.com/docs/api/1.1/post/sites/%24site/media/new/) endpoint.

So we could add a post like below:

```js
var site = wpcom.site('id');
site.add({ pretty: true }, { title: 'testing post' }, function(err, data){
// data object response
});
```

*Second* because we can pass `global` parameters like as `apiVersion` using this object.
```js
var site = wpcom.site('id');
site.addMediaUrls({ apiVersion: '1.1' }, 'http://url/to/add.png' , function(err, data){
// data object response
});
```

### Set api version `1.1` as default in all media endpoints

Due to new [media endpoints launched](https://operationapi.wordpress.com/2014/10/15/media-endpoints-1-1-launched/) I've set api version to `1.1` as default. The reason below.

### New media methods

With api version `1.1` we can upload files and set properties on the fly. Next examples how to upload media files.

```js
var site = wpcom.site('');

// upload a single file
site.addMediaFiles('file/to/upload', function(){ ... });

// ... or upload a file with its properties
site.addMediaFiles({
title: 'Nice file',
description: 'Just a simple testing description',
file: 'file/to/upload'
}, function(){ ... });

// ... or upload many files using an array
site.addMediaFiles(
'file/01/to/upload.png',
'file/02/to/upload.png',
{
title: 'Nice file',
description: 'Just a simple testing description',
file: 'file/03/to/upload'
}, function(){ ... });
```

Just fyi:
![](https://i.cloudup.com/q3OqpLO682.png)