Skip to content

Commit df1dee1

Browse files
committed
+ saveAs & load
1 parent 2bda318 commit df1dee1

File tree

7 files changed

+710
-345
lines changed

7 files changed

+710
-345
lines changed

README.md

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,15 +207,66 @@ FileAPI.event.on(el, 'change', function (evt/**Event*/){
207207
<a name="FileAPI.upload-short"></a>
208208
### upload(url`:String`, files`:Mixed`[, opts`:Object`])`:XmlHttpRequestPromise`
209209

210-
* url — a string containing the URL to which the request is sent.
210+
* url — a string containing the URL to which the request is sent
211211
* files — Array, Object or HTMLInput
212212

213213

214214
```js
215-
FileAPI.upload('./ctpl.php', files).done(function (xhr){
216-
var result = FileAPI.parseJSON(xhr.responseText);
217-
// ...
218-
});
215+
FileAPI.upload('./ctpl.php', files)
216+
.progress(function (evt){
217+
var p = (evt.loaded / evt.total)
218+
})
219+
.done(function (xhr){
220+
var result = FileAPI.parseJSON(xhr.responseText);
221+
// ...
222+
})
223+
;
224+
```
225+
226+
---
227+
228+
<a name="FileAPI.load"></a>
229+
### load(url`:String`[, opts`:Object`])`:XmlHttpRequestPromise`
230+
Load a remote file, by default as `Blob`.
231+
232+
* url — a string containing the URL to which the request is sent
233+
* opts — request options: { headers, data, withCredentials, responseType: "blob" }
234+
235+
```js
236+
var xhr = FileAPI.load("/files/dino.png")
237+
.progress(function (evt/**Event*/, xhr/**XmlHttpRequest*/){
238+
var p = (evt.loaded / evt.total);
239+
})
240+
.done(function (blob/**Blob*/, xhr/**XmlHttpRequest*/){
241+
// Success
242+
})
243+
.fail(function (statusText, xhr/**XmlHttpRequest*/){
244+
alert('Error: '+statusText);
245+
})
246+
;
247+
```
248+
249+
---
250+
251+
<a name="FileAPI.saveAs"></a>
252+
### saveAs(file`:String|File|Blob`[, name`:String`])`:XmlHttpRequestPromise`
253+
Save file on disk.
254+
255+
* file — a string containing the URL or File/Blob object
256+
* name — a file name
257+
258+
```js
259+
FileAPI.saveAs("/files/dino.png")
260+
.progress(function (evt){
261+
var p = (evt.loaded / evt.total);
262+
})
263+
.done(function (){
264+
// Success
265+
})
266+
.fail(function (err){
267+
alert('Error: '+err);
268+
})
269+
;
219270
```
220271

221272
---
@@ -1206,6 +1257,22 @@ Support dataURI as src for image.
12061257
### FileAPI.support.chunked`:Boolean`
12071258
Support chuncked upload.
12081259
1260+
<a name="FileAPI.support.saveAs"></a>
1261+
### FileAPI.support.saveAs`:Boolean`
1262+
Support `navigator.msSaveBlob`.
1263+
1264+
<a name="FileAPI.support.download"></a>
1265+
### FileAPI.support.download`:Boolean`
1266+
Support for attribute `download` in `a[href]`.
1267+
1268+
<a name="FileAPI.support.accept"></a>
1269+
### FileAPI.support.accept`:Boolean`
1270+
Support for attribute `accept` in `input[type="file"]`.
1271+
1272+
<a name="FileAPI.support.multiple"></a>
1273+
### FileAPI.support.multiple`:Boolean`
1274+
Support for attribute `multiple` in `input[type="file"]`.
1275+
12091276
---
12101277
12111278
<a name="flash"></a>

README.ru.md

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,61 @@ FileAPI.event.on(el, 'change', function (evt/**Event*/){
210210

211211

212212
```js
213-
FileAPI.upload('./ctpl.php', files).done(function (xhr){
214-
var result = FileAPI.parseJSON(xhr.responseText);
215-
// ...
216-
});
213+
FileAPI.upload('./ctpl.php', files)
214+
.progress(function (evt){
215+
var p = (evt.loaded / evt.total)
216+
})
217+
.done(function (xhr){
218+
var result = FileAPI.parseJSON(xhr.responseText);
219+
// ...
220+
})
221+
;
222+
```
223+
224+
---
225+
226+
<a name="FileAPI.load"></a>
227+
### load(url`:String`[, opts`:Object`])`:XmlHttpRequestPromise`
228+
Загрузить файл, по умолчанию как `Blob`.
229+
230+
* url — строка содержащая путь к файлу
231+
* opts — опции запроса: { headers, data, withCredentials, responseType: "blob" }
232+
233+
```js
234+
var xhr = FileAPI.load('./files/dino.png')
235+
.progress(function (evt/**Event*/, xhr/**XmlHttpRequest*/){
236+
var p = (evt.loaded / evt.total);
237+
})
238+
.done(function (blob/**Blob*/, xhr/**XmlHttpRequest*/){
239+
// Success
240+
})
241+
.fail(function (statusText, xhr/**XmlHttpRequest*/){
242+
alert('Error: '+statusText);
243+
})
244+
;
245+
```
246+
247+
---
248+
249+
<a name="FileAPI.saveAs"></a>
250+
### saveAs(file`:String|File|Blob`[, name`:String`])`:Promise`
251+
Сохранить файл на диск.
252+
253+
* file — путь к файлу или File/Blob объект
254+
* name — имя файла
255+
256+
```js
257+
FileAPI.saveAs("./files/dino.png")
258+
.progress(function (evt){
259+
var p = (evt.loaded / evt.total);
260+
})
261+
.done(function (){
262+
// Success
263+
})
264+
.fail(function (err){
265+
alert('Error: '+err);
266+
})
267+
;
217268
```
218269

219270
---
@@ -1206,6 +1257,23 @@ FileAPI.Camera.publish(el, function (err, cam/**FileAPI.Camera*/){
12061257
### FileAPI.support.chunked`:Boolean`
12071258
Возможность загрузки по частям.
12081259
1260+
<a name="FileAPI.support.saveAs"></a>
1261+
### FileAPI.support.saveAs`:Boolean`
1262+
Поддержка `navigator.msSaveBlob`.
1263+
1264+
<a name="FileAPI.support.download"></a>
1265+
### FileAPI.support.download`:Boolean`
1266+
Поддержка аттрибута `download` у `a[href]`.
1267+
1268+
<a name="FileAPI.support.accept"></a>
1269+
### FileAPI.support.accept`:Boolean`
1270+
Поддержка аттрибута `accept` у `input[type="file"]`.
1271+
1272+
<a name="FileAPI.support.multiple"></a>
1273+
### FileAPI.support.multiple`:Boolean`
1274+
Поддержка аттрибута `multiple` у `input[type="file"]`.
1275+
1276+
12091277
---
12101278
12111279
<a name="flash"></a>

0 commit comments

Comments
 (0)