summaryrefslogtreecommitdiffstats
path: root/doc/api/file.md
blob: 74120450b321bc608b034498483e73d781434275 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# /file API endpoints

**Table of Contents**

- [file/get_config](#fileget_config)
- [file/upload](#fileupload)
- [file/history](#filehistory)
- [file/delete](#filedelete)
- [file/create_multipaste](#filecreate_multipaste)

## file/get_config

Request method: GET
This is a public method and does not require an apikey.

Return some useful values that may differ between service installations/subsequent requests.

Success response:
```javascript
// Success response
responseSuccess.data = {
	// Maximum size of a single file
	"upload_max_size": int,

	// Maximum number of files sent with one request
	"max_files_per_request": int,

	// Maximum number of variables sent with one request
	// (be sure to account for the api key when using this)
	"max_input_vars": int,

	// Maximum size of a complete request
	"request_max_size": int,
}
```

Example:
```
> curl -s $base/file/get_config | json_pp
{
   "data" : {
	  "max_files_per_request" : 20,
	  "upload_max_size" : 1073741824,
	  "request_max_size" : 1073741824,
	  "max_input_vars" : 1000
   },
   "status" : "success"
}
```

| Version | Change                                     |
| ------- | ------                                     |
| 1.4.0   | Add data.{max_input_vars,request_max_size} |

## file/upload

Required access level: `basic`

Upload a new file.

| POST field    | Type | Comment                    |
| ----------    | ---- | -------                    |
| file[`<index>`] | File | Required. Arbitrary index. |

| error_id           | Message                                        | Note                                  |
| --------           | -------                                        | ----                                  |
| file/no-file       | No file was uploaded or unknown error occurred |                                       |
| file/upload-verify | Failed to verify uploaded file(s)              | This error provides additional detail |

```javascript
// Success response
responseSuccess.data = {
	"ids": [upload-id, ...],
	"urls": [String, ...],
}

// Error file/upload-verify
responseError.data = {
	String-formfield: {
		"filename": String, // from the request
		"formfield": String-formfield, // from the request, this is the same as the key of this object
		"message": String, // can be displayed to the user
	},
	...
}
```

Example:
```
> echo test | curl -s $base/file/upload -F apikey=$apikey -F "file=@-" | json_pp
{
   "status" : "success",
   "data" : {
	  "ids" : [
		 "uu28"
	  ],
	  "urls" : [
		 "http://filebin.localhost/uu28/"
	  ]
   }
}
```

## file/history

Return the currently available files/multipastes.

```javascript
// Definitions
item = {
	"id": upload-id,
	"filename": String,
	"mimetype": String,
	"date": Timestamp,
	"hash": String,
	"filesize": int,
	"thumbnail": String, // URL. only set when there is a thumbnail available
}

multipaste_item = {
	"url_id": upload-id,
	"id": upload-id, // this references item.id described above
	"date": Timestamp,
}

// Success response
responseSuccess.data = {
	"items": [item.id: item, ...],
	"multipaste_items": [multipaste_item.url_id: multipaste_item, ...],
	"total_size": int, // total size of all files (excluding duplicates)
}
```

Example:
```
> curl -s $base/file/history -F apikey=$apikey | json_pp
{
   "status" : "success",
   "data" : {
	  "multipaste_items" : {
		 "m-JcK" : {
			"items" : {
			   "oeL" : {
				  "id" : "oeL"
			   },
			   "7kn" : {
				  "id" : "7kn"
			   }
			},
			"url_id" : "m-JcK",
			"date" : "1444119317"
		 }
	  },
	  "total_size" : "164006",
	  "items" : {
		 "oeL" : {
			"id" : "oeL",
			"hash" : "098f6bcd4621d373cade4e832627b4f6",
			"date" : "1444119317",
			"filename" : "test2",
			"filesize" : "4",
			"mimetype" : "text/plain"
		 },
		 "7kn" : {
			"date" : "1444119317",
			"hash" : "6a72c253e8e9e6d01544f1c6b4573e6e",
			"id" : "7kn",
			"thumbnail" : "http://filebin.localhost/file/thumbnail/7kn",
			"mimetype" : "image/jpeg",
			"filesize" : "164001",
			"filename" : "Relax.jpg"
		 },
		 "l7p" : {
			"date" : "1444116077",
			"hash" : "cfcd208495d565ef66e7dff9f98764da",
			"id" : "l7p",
			"mimetype" : "application/octet-stream",
			"filesize" : "1",
			"filename" : "stdin"
		 }
	  }
   }
}
```

| Version | Change                                                                            |
| ------- | ------                                                                            |
| 2.0.0   | Add ''multipaste_item.date''. Remove ''multipaste_item.{multipaste_id,user_id}''. |
| 2.1.0   | Add ''item.thumbnail''                                                            |

## file/delete

Delete files or multipastes. Multipastes containing deleted files will also be silently removed.

Note: This function returns some errors in the success response.

| POST field | Type      | Comment                    |
| ---------- | ----      | -------                    |
| ids[`<index>`] | upload-id | Required. Arbitrary index. |

| error_id           | Message          | Note |
| --------           | -------          | ---- |
| file/delete/no-ids | No IDs specified |      |

```javascript
// Success response
responseSuccess.data = {
	"errors": {
		upload-id: {
			"id": upload-id, // this is the same as the key of this object
			"reason": String,
		},
		...
	},
	"deleted": {
		upload-id: {
			"id": upload-id, // this is the same as the key of this object
		},
		...
	},
	"total_count": int,
	"deleted_count": int,
}
```


Example:
```
> curl -s $base/file/delete -F apikey=$apikey -F "ids[1]=uu28" | json_pp
{
   "data" : {
      "errors" : [],
      "total_count" : 1,
      "deleted" : {
         "uu28" : {
            "id" : "uu28"
         }
      },
      "deleted_count" : 1
   },
   "status" : "success"
}
```

## file/create_multipaste

Required access level: `basic`

Create a new multipaste.

| POST field | Type      | Comment                                                                           |
| ---------- | ----      | -------                                                                           |
| ids[`<index>`] | upload-id | Required. Arbitrary index. This only accepts IDs of files, not other multipastes. |

| error_id                             | Message                         | Note                                  |
| --------                             | -------                         | ----                                  |
| file/create_multipaste/no-ids        | No IDs specified                |                                       |
| file/create_multipaste/duplicate-id  | Duplicate IDs are not supported |                                       |
| file/create_multipaste/verify-failed | Failed to verify ID(s)          | This error provides additional detail |

```javascript
// Success response
responseSuccess.data = {
    "url_id": upload-id,
    "url": String, // Complete URL to url_id
}

// Error file/create_multipaste/verify-failed
responseError.data = {
    upload-id: {
        "id": upload-id, // this is the same as the key of this object
        "reason": String,
    },
    ...
}
```

Example:
```
> curl -s $base/file/create_multipaste -F apikey=$apikey -F "ids[1]=uu28" | json_pp
{
   "data" : {
      "url" : "http://filebin.localhost/m-J250b/",
      "url_id" : "m-J25Ob"
   },
   "status" : "success"
}
```

| Version | Change                                                    |
| ------- | ------                                                    |
| 1.1.0   | Add url key to response                                   |
| 1.3.0   | Change required access level from ''apikey'' to ''basic'' |