app/assets/javascripts/activestorage.esm.js in activestorage-7.0.0.alpha2 vs app/assets/javascripts/activestorage.esm.js in activestorage-7.0.0.rc1

- old
+ new

@@ -506,18 +506,20 @@ return [].slice.call(value); } } class BlobRecord { - constructor(file, checksum, url) { + constructor(file, checksum, url, directUploadToken, attachmentName) { this.file = file; this.attributes = { filename: file.name, content_type: file.type || "application/octet-stream", byte_size: file.size, checksum: checksum }; + this.directUploadToken = directUploadToken; + this.attachmentName = attachmentName; this.xhr = new XMLHttpRequest; this.xhr.open("POST", url, true); this.xhr.responseType = "json"; this.xhr.setRequestHeader("Content-Type", "application/json"); this.xhr.setRequestHeader("Accept", "application/json"); @@ -541,11 +543,13 @@ } } create(callback) { this.callback = callback; this.xhr.send(JSON.stringify({ - blob: this.attributes + blob: this.attributes, + direct_upload_token: this.directUploadToken, + attachment_name: this.attachmentName })); } requestDidLoad(event) { if (this.status >= 200 && this.status < 300) { const {response: response} = this; @@ -602,23 +606,25 @@ } let id = 0; class DirectUpload { - constructor(file, url, delegate) { + constructor(file, url, serviceName, attachmentName, delegate) { this.id = ++id; this.file = file; this.url = url; + this.serviceName = serviceName; + this.attachmentName = attachmentName; this.delegate = delegate; } 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.serviceName, this.attachmentName); notify(this.delegate, "directUploadWillCreateBlobWithXHR", blob.xhr); blob.create((error => { if (error) { callback(error); } else { @@ -645,11 +651,11 @@ class DirectUploadController { constructor(input, file) { this.input = input; this.file = file; - this.directUpload = new DirectUpload(this.file, this.url, this); + this.directUpload = new DirectUpload(this.file, this.url, this.directUploadToken, this.attachmentName, this); this.dispatch("initialize"); } start(callback) { const hiddenInput = document.createElement("input"); hiddenInput.type = "hidden"; @@ -675,9 +681,15 @@ }); } } get url() { return this.input.getAttribute("data-direct-upload-url"); + } + get directUploadToken() { + return this.input.getAttribute("data-direct-upload-token"); + } + get attachmentName() { + return this.input.getAttribute("data-direct-upload-attachment-name"); } dispatch(name, detail = {}) { detail.file = this.file; detail.id = this.directUpload.id; return dispatchEvent(this.input, `direct-upload:${name}`, {