I have implemented Rails ActiveStorage on an ECS class
import { DirectUpload } from "@rails/activestorage";
function createDirectUpload(file, source, controller) {
return new DirectUpload(file, source.url, source.token, source.attachmentName, controller);
}
I instantiate a new DirectUpload in my constructor
constructor(source, file) {
this.directUpload = createDirectUpload(file, source, this);
this.source = source;
this.file = file;
}
start() {
this.source.fileUploader = this;
this.hiddenInput = this.createHiddenInput();
this.directUpload.create((error, attributes) => {
if (error) {
this.hiddenInput?.parentNode?.removeChild(this.hiddenInput);
this.emitDropzoneError(error);
} else {
this.hiddenInput.value = attributes.signed_id;
this.emitDropzoneSuccess();
}
});
}
directUploadWillStoreFileWithXHR(xhr) {
this.bindProgressEvent(xhr);
this.emitDropzoneUploading();
}
Even though start
is functioning correctly, the callback directUploadWillStoreFileWithXHR
is not being triggered.