/
loadBlob.js
37 lines (35 loc) · 1.25 KB
/
loadBlob.js
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
/*global define*/
define([
'./loadWithXhr'
], function(
loadWithXhr) {
"use strict";
/**
* Asynchronously loads the given URL as a blob. Returns a promise that will resolve to
* a Blob once loaded, or reject if the URL failed to load. The data is loaded
* using XMLHttpRequest, which means that in order to make requests to another origin,
* the server must have Cross-Origin Resource Sharing (CORS) headers enabled.
*
* @exports loadBlob
*
* @param {String|Promise} url The URL of the data, or a promise for the URL.
* @param {Object} [headers] HTTP headers to send with the requests.
*
* @returns {Promise} a promise that will resolve to the requested data when loaded.
*
* @see <a href='http://www.w3.org/TR/cors/'>Cross-Origin Resource Sharing</a>
* @see <a href='http://wiki.commonjs.org/wiki/Promises/A'>CommonJS Promises/A</a>
*
* @example
* // load a single URL asynchronously
* loadBlob('some/url').then(function(blob) {
* // use the data
* }, function() {
* // an error occurred
* });
*/
var loadBlob = function(url, headers) {
return loadWithXhr(url, 'blob', headers);
};
return loadBlob;
});