@scaleflex/widget-xhr-upload 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 scaleflex
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,200 @@
1
+ # `@scaleflex/widget-xhr-upload`
2
+
3
+ [![Plugins][plugins-image]](#plugins)
4
+ [![Website][filerobot-image]][sfx-url]
5
+ [![Version][filerobot-version]][version-url]
6
+ [![Scaleflex team][made-by-image]][sfx-url]
7
+ [![License][license-image]][license-url]
8
+ [![CodeSandbox][codeSandbox-image]][codeSandbox-url]
9
+
10
+ <div align='center'>
11
+ <img title="Scaleflex Widget logo" alt="Scaleflex Widget logo" src="https://cdn.scaleflex.com/plugins/filerobot-widget/assets/filerobot_widget_logo_with_fire.png?vh=b2ff09" width="140"/>
12
+ </div>
13
+
14
+ The XHR upload plugin for [Scaleflex Media Asset Widget](https://www.npmjs.com/package/@scaleflex/widget-core) handles uploading files in Multipart form uploading way and HTTP(s) protocol.
15
+
16
+ ## Usage
17
+
18
+ ### NPM
19
+
20
+ ```bash
21
+ npm install --save @scaleflex/widget-xhr-upload
22
+ ```
23
+
24
+ ### YARN
25
+
26
+ ```bash
27
+ yarn add @scaleflex/widget-xhr-upload
28
+ ```
29
+
30
+ then
31
+
32
+ ```js
33
+ import XHRUpload from '@scaleflex/widget-xhr-upload'
34
+ ...
35
+ ...
36
+ ...
37
+ scaleflexWidget.use(XHRUpload, propertiesObject)
38
+ ```
39
+
40
+ ### CDN
41
+
42
+ The plugin from CDN is found inside `Scaleflex` global object `Scaleflex.XHRUpload`
43
+
44
+ ```js
45
+ const XHRUpload = window.ScaleflexWidget.XHRUpload
46
+ ...
47
+ ...
48
+ ...
49
+ scaleflexWidget.use(XHRUpload, propertiesObject)
50
+ ```
51
+
52
+ ### Example
53
+
54
+ You can use upload in two ways:
55
+
56
+ - By using [Progress Panel](../@scaleflex/widget-progress-panel#Example) plugin, please check the example there.
57
+ - By using widget events, please check how to use events [here](..@scaleflex/widget-core/#upload) and see the example below:
58
+
59
+ ```js
60
+ const ScaleflexWidget = window.ScaleflexWidget;
61
+ const demoContainer = "scaleflex-tests-v5a";
62
+ const demoSecurityTemplateId = "......";
63
+
64
+ const scaleflexWidget = ScaleflexWidget.Core({
65
+ securityTemplateId: demoSecurityTemplateId,
66
+ container: demoContainer,
67
+ dev: false, // optional, default: false
68
+ });
69
+
70
+ const Explorer = ScaleflexWidget.Explorer;
71
+ const XHRUpload = ScaleflexWidget.XHRUpload;
72
+
73
+ scaleflexWidget
74
+ .use(Explorer, { target: "#scaleflex-widget", inline: true })
75
+ .use(XHRUpload);
76
+
77
+ // events
78
+ scaleflexWidget.on("upload", () => {
79
+ // trigger when upload is clicked inside explorer
80
+ });
81
+ scaleflexWidget.on("upload-started", () => {
82
+ // trigger when upload starts
83
+ });
84
+ scaleflexWidget.on("upload-progress", () => {
85
+ // trigger when upload is progressing
86
+ });
87
+ scaleflexWidget.on("upload-success", () => {
88
+ // trigger when upload is completed
89
+ });
90
+ scaleflexWidget.on("upload-error", () => {
91
+ // trigger when upload has an error
92
+ });
93
+ ```
94
+
95
+ ## Properties
96
+
97
+ ### `uploadToFolderPath`
98
+
99
+ <u>Type:</u> `string`.
100
+
101
+ <u>Default:</u> `null`
102
+
103
+ The path of the folder that will be used in uploading to, if this property is provided it will override the current opened folder path and files would be uploaded to this path.
104
+
105
+ > Note: you shouldn't provide `folder=...` in the `uploadQueryParams` if you want to use this property or `uploadQueryParams` will override this property's value.
106
+
107
+ ### `uploadQueryParams: string`
108
+
109
+ <u>Type:</u> `string`.
110
+
111
+ <u>Default:</u> `''`
112
+
113
+ The query to be appended to the upload url, ex. `../upload?`**`extra=hello&foo=bar`**.
114
+
115
+ ### `limit`
116
+
117
+ <u>Type:</u> `number`.
118
+
119
+ <u>Default:</u> `0`
120
+
121
+ Limit the number of uploads' requests handled at the same if left `0` then there is no limit.
122
+
123
+ ### `timeout`
124
+
125
+ <u>Type:</u> `number`.
126
+
127
+ <u>Default:</u> `60 * 1000`
128
+
129
+ Defines the timeout for not receiving upload events or having no uploading's progress after that amount of milliseconds it abort the upload assuming there is a problem with the connection, if set to `0` this feature will be disabled.
130
+
131
+ ### `headers: `
132
+
133
+ <u>Type:</u> `object`.
134
+
135
+ <u>Default:</u> `{X-Scaleflex-Key: '...'}`
136
+
137
+ If you want to customize the headers of the upload requests are being sent to the backend.
138
+
139
+ ### `info`
140
+
141
+ <u>Type:</u> `object`.
142
+
143
+ <u>Default:</u> `undefined`
144
+
145
+ If you want to pass some info to the file pass an object with the needed info to this property and it would be considered while uploading the file, example: `{ recipe_id: 10 }`.
146
+
147
+ > Note: Applied only for local uploads <!-- maybe, because the backend doesn't support all info data fields? -->
148
+
149
+ ### `addInfoCallback`
150
+
151
+ <u>Type:</u> `function`.
152
+
153
+ <u>Default:</u> `undefined`
154
+
155
+ If you want to pass some info to the file after doing some operation/functionality, pass a function that has `file` object as a parameter that contains the file's details and returns an object of the info data to be passed and saved to the file while uploading otherwise the function won't be considered.
156
+
157
+ Example, `(file) => (file.name === 'first' ? { file_order: 'first' } : false)`
158
+
159
+ > Note: Applied only for local uploads <!-- maybe, because the backend doesn't support all info data fields? -->
160
+
161
+ ### `meta`
162
+
163
+ <u>Type:</u> `object`.
164
+
165
+ _default_: `undefined`
166
+
167
+ Add some meta in the file object by providing the meta as object to this property , example: `{ recipe_category: 'Vegetables' }`.
168
+
169
+ > Note: Applied only for local uploads
170
+
171
+ ### `locale`
172
+
173
+ <u>Type:</u> `object`.
174
+
175
+ <u>Default:</u>
176
+
177
+ ```js
178
+ {
179
+ strings: {
180
+ timedOut: "Upload stalled for %{seconds} seconds, aborting.";
181
+ }
182
+ }
183
+ ```
184
+
185
+ Customizing some of the translations or the language's strings and replace the default locale.
186
+
187
+ <!-- Variables -->
188
+
189
+ [npm-url]: https://www.npmjs.com/package/@scaleflex/widget-xhr-upload
190
+ [license-url]: https://opensource.org/licenses/MIT
191
+ [sfx-url]: https://www.scaleflex.com/
192
+ [version-url]: https://www.npmjs.com/package/@scaleflex/widget-xhr-upload
193
+ [codeSandbox-url]: https://codesandbox.io/s/filerobot-widget-v3-c5l9th
194
+ [npm-image]: https://img.shields.io/npm/v/@telus/remark-config.svg?style=for-the-badge&logo=npm
195
+ [license-image]: https://img.shields.io/badge/license-MIT-blue.svg?style=for-the-badge
196
+ [made-by-image]: https://img.shields.io/badge/%3C%2F%3E%20with%20%E2%99%A5%20by-the%20Scaleflex%20team-6986fa.svg?style=for-the-badge
197
+ [plugins-image]: https://img.shields.io/static/v1?label=Scaleflex&message=Plugins&color=yellow&style=for-the-badge
198
+ [filerobot-image]: https://img.shields.io/static/v1?label=Scaleflex&message=website&color=orange&style=for-the-badge
199
+ [filerobot-version]: https://img.shields.io/npm/v/@scaleflex/widget-xhr-upload?label=Version&style=for-the-badge&logo=npm
200
+ [codeSandbox-image]: https://img.shields.io/badge/CodeSandbox-black?style=for-the-badge&logo=CodeSandbox