Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var xhr = new XMLHttpRequest();
- xhr.open('GET', 'blob:http%3A//your.blob.url.here', true);
- xhr.responseType = 'blob';
- xhr.onload = function(e) {
- if (this.status == 200) {
- var myBlob = this.response;
- // myBlob is now the blob that the object URL pointed to.
- }
- };
- xhr.send();
- xhr.responseType = 'arraybuffer';
- canvas.toBlob(function(my_file){
- //.toBlob is only implemented in > FF18 but there is a polyfill
- //for other browsers https://github.com/blueimp/JavaScript-Canvas-to-Blob
- var myBlob = (my_file);
- })
- /**
- *
- * jquery.binarytransport.js
- *
- * @description. jQuery ajax transport for making binary data type requests.
- * @version 1.0
- * @author Henry Algus <henryalgus@gmail.com>
- *
- */
- // use this transport for "binary" data type
- $.ajaxTransport("+binary", function (options, originalOptions, jqXHR) {
- // check for conditions and support for blob / arraybuffer response type
- if (window.FormData && ((options.dataType && (options.dataType == 'binary')) || (options.data && ((window.ArrayBuffer && options.data instanceof ArrayBuffer) || (window.Blob && options.data instanceof Blob))))) {
- return {
- // create new XMLHttpRequest
- send: function (headers, callback) {
- // setup all variables
- var xhr = new XMLHttpRequest(),
- url = options.url,
- type = options.type,
- async = options.async || true,
- // blob or arraybuffer. Default is blob
- dataType = options.responseType || "blob",
- data = options.data || null,
- username = options.username || null,
- password = options.password || null;
- xhr.addEventListener('load', function () {
- var data = {};
- data[options.dataType] = xhr.response;
- // make callback and send data
- callback(xhr.status, xhr.statusText, data, xhr.getAllResponseHeaders());
- });
- xhr.open(type, url, async, username, password);
- // setup custom headers
- for (var i in headers) {
- xhr.setRequestHeader(i, headers[i]);
- }
- xhr.responseType = dataType;
- xhr.send(data);
- },
- abort: function () {
- jqXHR.abort();
- }
- };
- }
- });
- function downloadArt(url)
- {
- $.ajax(url, {
- dataType: "binary",
- processData: false
- }).done(function (data) {
- // just my logic to name/create files
- var filename = url.substr(url.lastIndexOf('/') + 1) + '.png';
- var blob = new Blob([data], { type: 'image/png' });
- saveAs(blob, filename);
- });
- }
- axios({
- method: 'get',
- url: file[0].preview, // blob url eg. blob:http://127.0.0.1:8000/e89c5d87-a634-4540-974c-30dc476825cc
- responseType: 'blob'
- }).then(function(response){
- var reader = new FileReader();
- reader.readAsDataURL(response.data);
- reader.onloadend = function() {
- var base64data = reader.result;
- self.props.onMainImageDrop(base64data)
- }
- })
Add Comment
Please, Sign In to add comment