1 |
|
2 | # Media
|
3 |
|
4 | `Media` handler class.
|
5 |
|
6 | ### Create a `Media` instance from Site
|
7 |
|
8 | ```js
|
9 | var wpcom = require('wpcom')('<your-token>');
|
10 | var media = wpcom.site('<site-id>').media('<media-id>');
|
11 | });
|
12 | ```
|
13 |
|
14 | ## API
|
15 |
|
16 | ### Media(id, site, WPCOM)
|
17 |
|
18 | Create a new `Media` instance giving `id`, `site-id` and `WPCOM` instance.
|
19 |
|
20 | ```js
|
21 | var media = Media('<id>', '<site-id>', WPCOM);
|
22 | ```
|
23 |
|
24 | ### Media.id(id)
|
25 |
|
26 | Set media `id`
|
27 |
|
28 | ### Media#get([query, ]fn)
|
29 |
|
30 | Request a single media item
|
31 |
|
32 | ```js
|
33 | media.get(function(err, data){
|
34 | // media data object
|
35 | });
|
36 | ```
|
37 |
|
38 | ### Media#addFiles([query, ]files, fn)
|
39 |
|
40 | ```js
|
41 | var media = Media('<id>', '<site-id>', WPCOM);
|
42 |
|
43 | // add a media file using a STRING
|
44 | media.add('/file/to/upload.png', function(err, file){
|
45 | // file data object
|
46 | });
|
47 |
|
48 | // add a media file using an OBJECT
|
49 | media.add({
|
50 | title: 'Nice picture',
|
51 | description: 'A nice pictures uploaded from a FILE',
|
52 | file: '/file/to/upload.png'
|
53 | }, function(err, file){
|
54 | // file data object
|
55 | });
|
56 |
|
57 | // add many media files using an Array
|
58 | media.add([
|
59 | 'file/01/to/upload.png',
|
60 | {
|
61 | title: 'Nice picture',
|
62 | description: 'A nice pictures uploaded from a FILE',
|
63 | file: '/file/02/to/upload.png'
|
64 | },
|
65 | 'file/03/to/upload.png'
|
66 | ], function(err, file){
|
67 | // file data object
|
68 | });
|
69 | ```
|
70 |
|
71 | ### Media#addUrls([query, ]media, fn)
|
72 |
|
73 | ```js
|
74 | var media = Media('<id>', '<site-id>', WPCOM);
|
75 |
|
76 | // add a media url using a String
|
77 | media.add('http://file/to/upload.png', function(err, file){
|
78 | // file data object
|
79 | });
|
80 |
|
81 | // add a media url using an OBJECT
|
82 | media.add({
|
83 | title: 'Nice picture',
|
84 | description: 'A nice pictures uploaded from an URL',
|
85 | url: 'http://file/to/upload.png'
|
86 | }, function(err, file){
|
87 | // file data object
|
88 | });
|
89 |
|
90 | // add many media url using an Array
|
91 | media.add([
|
92 | 'http://file/01/to/upload.png',
|
93 | {
|
94 | title: 'Nice picture',
|
95 | description: 'A nice pictures uploaded from an URL',
|
96 | url: 'http://file/02/to/upload.png'
|
97 | },
|
98 | 'http://file/03/to/upload.png'
|
99 | ], function(err, file){
|
100 | // file data object
|
101 | });
|
102 | ```
|
103 |
|
104 | ### Media#delete(fn) - Media#delete(fn)
|