Skip to content

Commit 1ede363

Browse files
committed
update doc and uploader refactor, related #47
1 parent c23231a commit 1ede363

File tree

3 files changed

+66
-62
lines changed

3 files changed

+66
-62
lines changed

API.md

Lines changed: 54 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
## angular-filemanager API docs
22

3-
#### Listing
4-
URL: fileManagerConfig.listUrl, Method: POST
5-
##### JSON Request content
3+
#### Listing (URL: fileManagerConfig.listUrl, Method: POST)
4+
5+
**JSON Request content**
66
```json
77
{ "params": {
88
"mode": "list",
99
"onlyFolders": false,
1010
"path": "/public_html"
1111
}}
1212
```
13-
##### JSON Response
13+
**JSON Response**
1414
```json
1515
{ "result": [
1616
{
@@ -35,97 +35,90 @@
3535
]}
3636
```
3737
--------------------
38-
#### Rename / Move
39-
URL: fileManagerConfig.renameUrl, Method: POST
40-
##### JSON Request content
38+
#### Rename / Move (URL: fileManagerConfig.renameUrl, Method: POST)
39+
**JSON Request content**
4140
```json
4241
{ "params": {
4342
"mode": "rename",
4443
"path": "/public_html/index.php",
4544
"newPath": "/public_html/index2.php"
4645
}}
4746
```
48-
##### JSON Response
47+
**JSON Response**
4948
```json
5049
{ "result": { "success": true, "error": null } }
5150
```
5251
--------------------
53-
#### Copy
54-
URL: fileManagerConfig.copyUrl, Method: POST
55-
##### JSON Request content
52+
#### Copy (URL: fileManagerConfig.copyUrl, Method: POST)
53+
**JSON Request content**
5654
```json
5755
{ "params": {
5856
"mode": "copy",
5957
"path": "/public_html/index.php",
6058
"newPath": "/public_html/index-copy.php"
6159
}}
6260
```
63-
##### JSON Response
61+
**JSON Response**
6462
```json
6563
{ "result": { "success": true, "error": null } }
6664
```
6765
--------------------
68-
#### Remove
69-
URL: fileManagerConfig.removeUrl, Method: POST
70-
##### JSON Request content
66+
#### Remove (URL: fileManagerConfig.removeUrl, Method: POST)
67+
**JSON Request content**
7168
```json
7269
{ "params": {
7370
"mode": "delete",
7471
"path": "/public_html/index.php",
7572
}}
7673
```
77-
##### JSON Response
74+
**JSON Response**
7875
```json
7976
{ "result": { "success": true, "error": null } }
8077
```
8178
--------------------
82-
#### Edit file
83-
URL: fileManagerConfig.editUrl, Method: POST
84-
##### JSON Request content
79+
#### Edit file (URL: fileManagerConfig.editUrl, Method: POST)
80+
**JSON Request content**
8581
```json
8682
{ "params": {
8783
"mode": "savefile",
8884
"content": "<?php echo random(); ?>",
8985
"path": "/public_html/index.php",
9086
}}
9187
```
92-
##### JSON Response
88+
**JSON Response**
9389
```json
9490
{ "result": { "success": true, "error": null } }
9591
```
9692
--------------------
97-
#### Get content of a file
98-
URL: fileManagerConfig.getContentUrl, Method: POST
99-
##### JSON Request content
93+
#### Get content of a file (URL: fileManagerConfig.getContentUrl, Method: POST)
94+
**JSON Request content**
10095
```json
10196
{ "params": {
10297
"mode": "editfile",
10398
"path": "/public_html/index.php"
10499
}}
105100
```
106-
##### JSON Response
101+
**JSON Response**
107102
```json
108103
{ "result": "<?php echo random(); ?>" }
109104
```
110105
--------------------
111-
#### Create folder
112-
URL: fileManagerConfig.createFolderUrl, Method: POST
113-
##### JSON Request content
106+
#### Create folder (URL: fileManagerConfig.createFolderUrl, Method: POST)
107+
**JSON Request content**
114108
```json
115109
{ "params": {
116110
"mode": "addfolder",
117111
"name": "new-folder",
118112
"path": "/public_html"
119113
}}
120114
```
121-
##### JSON Response
115+
**JSON Response**
122116
```json
123117
{ "result": { "success": true, "error": null } }
124118
```
125119
--------------------
126-
#### Set permissions
127-
URL: fileManagerConfig.permissionsUrl, Method: POST
128-
##### JSON Request content
120+
#### Set permissions (URL: fileManagerConfig.permissionsUrl, Method: POST)
121+
**JSON Request content**
129122
```json
130123
{ "params": {
131124
"mode": "changepermissions",
@@ -135,29 +128,27 @@
135128
"recursive": false
136129
}}
137130
```
138-
##### JSON Response
131+
**JSON Response**
139132
```json
140133
{ "result": { "success": true, "error": null } }
141134
```
142135
--------------------
143-
#### Compress file
144-
URL: fileManagerConfig.compressUrl, Method: POST
145-
##### JSON Request content
136+
#### Compress file (URL: fileManagerConfig.compressUrl, Method: POST)
137+
**JSON Request content**
146138
```json
147139
{ "params": {
148140
"mode": "compress",
149141
"path": "/public_html/compressed.zip",
150142
"destination": "/public_html/backups"
151143
}}
152144
```
153-
##### JSON Response
145+
**JSON Response**
154146
```json
155147
{ "result": { "success": true, "error": null } }
156148
```
157149
--------------------
158-
#### Extract file
159-
URL: fileManagerConfig.extractUrl, Method: POST
160-
##### JSON Request content
150+
#### Extract file (URL: fileManagerConfig.extractUrl, Method: POST)
151+
**JSON Request content**
161152
```json
162153
{ "params": {
163154
"mode": "extract",
@@ -166,36 +157,49 @@
166157
"sourceFile": "/public_html/compressed.zip"
167158
}}
168159
```
169-
##### JSON Response
160+
**JSON Response**
170161
```json
171162
{ "result": { "success": true, "error": null } }
172163
```
173164
--------------------
174-
#### Upload file
175-
URL: fileManagerConfig.uploadUrl, Method: POST, Content-Type: multipart/form-data
176-
Unlimited file upload, each item will be enumerated as file-1, file-2, etc.
177-
##### Http post params
165+
#### Upload file (URL: fileManagerConfig.uploadUrl, Method: POST, Content-Type: multipart/form-data)
166+
167+
**Http post request payload**
178168
```
179-
[fileManagerConfig.uploadUrl]?destination=/public_html/image.jpg&file-1={..}&file-2={...}
169+
------WebKitFormBoundaryqBnbHc6RKfXVAf9j
170+
Content-Disposition: form-data; name="destination"
171+
/
172+
173+
------WebKitFormBoundaryqBnbHc6RKfXVAf9j
174+
Content-Disposition: form-data; name="file-0"; filename="github.txt"
175+
Content-Type: text/plain
180176
```
181-
##### JSON Response
177+
**JSON Response**
182178
```json
183179
{ "result": { "success": true, "error": null } }
184180
```
181+
182+
Unlimited file items to upload, each item will be enumerated as file-0, file-1, etc.
183+
184+
For example, you may retrieve the file in PHP using:
185+
```php
186+
$destination = $_POST['destination'];
187+
$_FILES['file-0'] or foreach($_FILES)
188+
```
185189
--------------------
186-
#### Download / Preview file
187-
URL: fileManagerConfig.downloadFileUrl, Method: GET
188-
##### Http query params
190+
#### Download / Preview file (URL: fileManagerConfig.downloadFileUrl, Method: GET)
191+
**Http query params**
189192
```
190193
[fileManagerConfig.downloadFileUrl]?mode=download&preview=true&path=/public_html/image.jpg
191194
```
192-
##### Response
195+
**Response**
193196
```
194197
-File content
195198
```
196199
--------------------
197200
##### Errors / Exceptions
198201
Any backend error should be with an error 500 HTTP code.
202+
199203
Btw, you can also report errors with a 200 response both using this json structure
200204
```json
201205
{ "result": {

assets/js/fileuploader.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@
44

55
var self = this;
66
self.requesting = false;
7-
self.upload = function(fileList, path, success, error) {
8-
var form = new window.FormData();
9-
7+
self.upload = function(fileList, path) {
8+
var form = new window.FormData();
109
form.append('destination', '/' + path.join('/'));
11-
for (var file in fileList) {
12-
var fileObj = fileList[file];
13-
typeof fileObj === 'object' && form.append('file-' + (1 + parseInt(file, null)), fileObj);
10+
11+
for (var i = 0; i < fileList.length; i++) {
12+
var fileObj = fileList.item(i);
13+
fileObj instanceof window.File && form.append('file-' + i, fileObj);
1414
}
1515

1616
self.requesting = true;
1717
return $http.post(fileManagerConfig.uploadUrl, form, {
1818
transformRequest: angular.identity,
19-
headers: {'Content-Type': undefined}
19+
headers: {
20+
"Content-Type": undefined
21+
}
2022
}).success(function(data) {
21-
self.requesting = false;
22-
typeof success === 'function' && success(data);
23+
self.inprocess = false;
2324
}).error(function(data) {
24-
self.requesting = false;
25-
typeof error === 'function' && error(data);
25+
self.inprocess = false;
2626
});
2727
};
2828
}]);

0 commit comments

Comments
 (0)