app/assets/javascripts/activestorage.js in activestorage-7.0.8.6 vs app/assets/javascripts/activestorage.js in activestorage-7.1.0.beta1
- old
+ new
@@ -501,11 +501,11 @@
} else {
return [].slice.call(value);
}
}
class BlobRecord {
- constructor(file, checksum, url) {
+ constructor(file, checksum, url, customHeaders = {}) {
this.file = file;
this.attributes = {
filename: file.name,
content_type: file.type || "application/octet-stream",
byte_size: file.size,
@@ -515,10 +515,13 @@
this.xhr.open("POST", url, true);
this.xhr.responseType = "json";
this.xhr.setRequestHeader("Content-Type", "application/json");
this.xhr.setRequestHeader("Accept", "application/json");
this.xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
+ Object.keys(customHeaders).forEach((headerKey => {
+ this.xhr.setRequestHeader(headerKey, customHeaders[headerKey]);
+ }));
const csrfToken = getMetaValue("csrf-token");
if (csrfToken != undefined) {
this.xhr.setRequestHeader("X-CSRF-Token", csrfToken);
}
this.xhr.addEventListener("load", (event => this.requestDidLoad(event)));
@@ -594,23 +597,24 @@
this.callback(`Error storing "${this.file.name}". Status: ${this.xhr.status}`);
}
}
let id = 0;
class DirectUpload {
- constructor(file, url, delegate) {
+ constructor(file, url, delegate, customHeaders = {}) {
this.id = ++id;
this.file = file;
this.url = url;
this.delegate = delegate;
+ this.customHeaders = customHeaders;
}
create(callback) {
FileChecksum.create(this.file, ((error, checksum) => {
if (error) {
callback(error);
return;
}
- const blob = new BlobRecord(this.file, checksum, this.url);
+ const blob = new BlobRecord(this.file, checksum, this.url, this.customHeaders);
notify(this.delegate, "directUploadWillCreateBlobWithXHR", blob.xhr);
blob.create((error => {
if (error) {
callback(error);
} else {
@@ -814,9 +818,11 @@
start();
}
}
setTimeout(autostart, 1);
exports.DirectUpload = DirectUpload;
+ exports.DirectUploadController = DirectUploadController;
+ exports.DirectUploadsController = DirectUploadsController;
exports.start = start;
Object.defineProperty(exports, "__esModule", {
value: true
});
}));