You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+47-13
Original file line number
Diff line number
Diff line change
@@ -11,11 +11,12 @@ Image Block for the [CodeX Editor](https://ifmo.su/editor).
11
11
- Uploading file from the device
12
12
- Pasting copied content from the web
13
13
- Pasting images by drag-n-drop
14
+
- Pasting files and screenshots from Clipboard
14
15
- Allows to add border, background
15
-
- Allows to stretch image to the container's full-width
16
+
- Allows to stretch image to the container's full-width
16
17
17
18
**Note** This Tool requires server-side implementation for file uploading. See [backend response format](#server-format) for more details.
18
-
19
+
19
20
## Installation
20
21
21
22
### Install via NPM
@@ -52,29 +53,37 @@ Add a new Tool to the `tools` property of the CodeX Editor initial config.
52
53
```javascript
53
54
var editor =CodexEditor({
54
55
...
55
-
56
+
56
57
tools: {
57
58
...
58
59
image: {
59
60
class: ImageTool,
60
61
config: {
61
-
url:'http://localhost:8008/', // Your backend uploader endpoint
62
+
endpoints: {
63
+
byFile:'http://localhost:8008/uploadFile', // Your backend file uploader endpoint
64
+
byUrl:'http://localhost:8008/fetchUrl', // Your endpoint that provides uploading by Url
65
+
}
62
66
}
63
67
}
64
68
}
65
-
69
+
66
70
...
67
71
});
68
72
```
69
73
70
-
## Config Params
74
+
## Config Params
75
+
76
+
Image Tool supports these configuration parameters:
71
77
72
78
| Field | Type | Description |
73
79
| ----- | -------- | ------------------ |
74
-
|url |`string`|**Required**Path for file uploading |
80
+
|endpoints |`{byFile: string, byUrl: string}`|**Required**Endpoints for file uploading. <br> Contains 2 fields: <br> __byFile__ - for file uploading <br> __byUrl__ - for uploading by URL|
75
81
| field |`string`| (default: `image`) Name of uploaded image field in POST request |
76
82
| types |`string`| (default: `image/*`) Mime-types of files that can be [accepted with file selection](https://github.com/codex-team/ajax#accept-string).|
83
+
| additionalRequestData |`object`| Object with any data you want to send with uploading requests |
84
+
| additionalRequestHeaders |`object`| Object with any custom headers which will be added to request. [See example](https://github.com/codex-team/ajax/blob/e5bc2a2391a18574c88b7ecd6508c29974c3e27f/README.md#headers-object)|
77
85
| captionPlaceholder |`string`| (default: `Caption`) Placeholder for Caption input |
86
+
| buttonContent |`string`| Allows to override HTML content of «Select file» button |
78
87
79
88
## Tool's settings
80
89
@@ -116,10 +125,19 @@ This Tool returns `data` with following format
116
125
117
126
## Backend response format <aname="server-format"></a>
118
127
119
-
This Tool works by following scheme:
128
+
This Tool works by one of the following schemes:
129
+
130
+
1. Uploading files from the device
131
+
2. Uploading by URL (handle image-like URL's pasting)
132
+
3. Uploading by drag-n-drop file
133
+
4. Uploading by pasting from Clipboard
134
+
135
+
### Uploading files from device <aname="from-device"></a>
136
+
137
+
Scenario:
120
138
121
139
1. User select file from the device
122
-
2. Tool sends it to **your** backend
140
+
2. Tool sends it to **your** backend (on `config.endpoint.byFile` route)
123
141
3. Your backend should save file and return file data with JSON at specified format.
124
142
4. Image tool shows saved image and stores server answer
125
143
@@ -140,8 +158,24 @@ Response of your uploader **should** cover following format:
140
158
141
159
**success** - uploading status. 1 for successful, 0 for failed
142
160
143
-
**file** - uploaded file data. **Must** contain an `url` field with full public path to the uploaded image.
144
-
Also, can contain any additional fields you want to store. For example, width, height, id etc.
145
-
All additional fields will be saved at the `file` object of output data.
161
+
**file** - uploaded file data. **Must** contain an `url` field with full public path to the uploaded image.
162
+
Also, can contain any additional fields you want to store. For example, width, height, id etc.
163
+
All additional fields will be saved at the `file` object of output data.
164
+
165
+
### Uploading by pasted URL
166
+
167
+
Scenario:
168
+
169
+
1. User pastes an URL of the image file to the Editor
170
+
2. Editor pass pasted string to the Image Tool
171
+
3. Tool sends it to **your** backend (on `config.endpoint.byUrl` route) via 'url' POST-parameter
172
+
3. Your backend should accept URL, **download and save the original file by passed URL** and return file data with JSON at specified format.
173
+
4. Image tool shows saved image and stores server answer
174
+
175
+
Response of your uploader should be at the same format as described at «[Uploading files from device](#from-device)» section
176
+
177
+
178
+
### Uploading by drag-n-drop or from Clipboard
146
179
147
-
180
+
Your backend will accept file as FormData object in field name, specified by `config.field` (by default, «`image`»).
181
+
You should save it and return the same response format as described above.
0 commit comments