DirectUpload is failing to trigger directUploadWillStoreFileWithXHR for file storage

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.

Answer №1

If you want to monitor the status of the file upload, simply include a third parameter in the DirectUpload constructor

new DirectUpload(file, source.url, this)

Include it as the fifth parameter like this

return new DirectUpload(file, source.url, source.token, source.attachmentName, controller);

Your initial setup should resemble the following:

import { DirectUpload } from "@rails/activestorage";

function uploadFile(file, source, controller) {
  return new DirectUpload(file, source.url, controller);
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue encountered while retrieving JSON data from Github

I am currently using d3.json to retrieve a JSON link from the Enterprise GitHub (within the same repository/folder as the JavaScript file). d3.json("https://raw.github.exampleEnterprise.com/path/to/repo/data.json?token=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ...

Unable to find the locally stored directory in the device's file system using Nativescript file-system

While working on creating an audio file, everything seems to be running smoothly as the recording indicator shows no errors. However, once the app generates the directory, I am unable to locate it in the local storage. The code I am using is: var audioFo ...

Add a parameter within a loop using JavaScript

I am currently working on a function with a parameter called menu. removeChildCheck:function(menu){ let removeArrayValues = []; for(var i=0; i < this.checkbox.menu.length; i++){ removeArrayValues.push(this.checkbox.menu[i].value); ...

How can I retrieve the Azure subscription IDs of the currently logged in user using @azure/msal-angular?

I successfully authenticated a user using @azure/msal-angular and received the id_Token, access_Token and tenant Id. Now I am looking to retrieve the logged in user's azure subscriptions. Is there a way to achieve this through msal or are there any Ja ...

What is the best way to create query strings for AJAX URL using jQuery or JavaScript?

At the moment, I am implementing ajax and jquery to dynamically update search results based on different filtering categories within a form. My challenge lies in the fact that I aim to pass varying variables to the URL used for ajax, derived from checkbox ...

Track the number of times a button is clicked to generate a prominent "Main Event" section

Currently, I am working on a Tourism website that showcases numerous tours. Utilizing WordPress, I have established a custom post type titled Tours. Each tour is equipped with a Book Now button, which has been generated as a custom meta box. This button d ...

One the year is chosen, it will be automatically hidden and no longer available for selection

<div ng-repeat="localcost in vm.project.localCosts" layout="column"> <md-select name="localcost_{{$index}}"ng-model="localcost.year" flex> <md-option ng-repeat="years in vm.getYears()" ng-value="years">{{years}}< ...

Despite declaring a default export, the code does not include one

Software decays over time. After making a small modification to a GitHub project that was three years old, the rebuild failed due to automatic security patches. I managed to fix everything except for an issue with a default import. The specific error mess ...

What is the best way to send information from child components to their parent in React

I'm facing a scenario where I need to increase the parent value based on actions taken in the children components. Parent Component: getInitialState :function(){ return {counter:0} }, render(){ <CallChild value={this.state.counter}/> ...

Managing dates in Coordinated Universal Time (UTC) on the

Let's address the current situation: The occurred_at dates are stored in UTC in the database. I am developing an API method using Laravel to retrieve records with these occurred_at fields. The JSON output currently displays the dates in a string form ...

What is the best way to utilize this resulting value as an input?

I am trying to generate a random number using math.random and use that value in the following script: let bday = Math.floor( Math.random() * (30 - 1 + 1) + 1 ); await test.page.select('select[name="day_select"]',bday); However, I am ...

Enabling or disabling mouse scroll wheel function across various web browsers

I am facing an issue with enabling/disabling mouse scroll using two buttons: "disable_scroll" and "enable_scroll". The code for disabling scroll works perfectly fine: var cancelscroll = function(e) { e.preventDefault(); }; $("#disable_scroll"). ...

Transferring the data entered into an input field to a PHP script, in order to retrieve and display the value with JavaScript, unfortunately results in a

My situation involves a form that consists of only one input text field (search_term) and a submit button. The goal is to enter a keyword into the input field, click Submit, have the keyword sent to a php script for json encoding, and then returned back t ...

The battle between AngularJS, Factory, $scope, and promises intensifies

Currently facing a challenge with the code snippet below: app.factory('sfAttachment', ['$http', '$q', '$window', '$rootScope', function($http, $q, $window, $rootScope) { var attachment = {}; //Functio ...

Navigating to User's Specific Info Page using Node.js

Would love some input on my current issue. I have a table featuring a list of users, and my goal is to display user information in detail whenever a user (which corresponds to a row in the table) is clicked. The process involves identifying which user was ...

Error: Attempting to access the 'getProvider' property of an undefined variable

I am encountering an error that says "property of undefined (reading getProvider)" while deploying my function to Firebase. I am currently trying to figure out how to obtain the auth instance. When I attempt to use firebase.auth, it results in another er ...

Simple steps to load various json files into separate json objects using node.js

I am new to working with Json and node.js My goal is to load a json file into a JsonObject using node.js, but I have been struggling to accomplish this task. I have created two files, one named server.js and the other jsonresponse.json. My objective is t ...

Problem encountered while trying to import npm module in React Native

Working on developing an android app and currently in the process of importing the spotify-web-api-node module. In my index.android.js file, I have added the following line: import SpotifyWebApi from 'spotify-web-api-node'; However, when I try ...

How can I extract particular combinations from a PHP array?

I have a unique question that is quite specific and despite searching online, I couldn't find an answer. So, I decided to seek advice here. Imagine my webpage has three sliders: one for selecting color options for a square, another for a circle, and ...

Exploring ways to overlay 2D text onto my Blender-created 3D model

Having created a 3D model with Blender, I am trying to overlay 2D text over the different meshes of the model. While I have successfully changed the colors of the meshes based on their indices using diffuse.color, I am struggling to draw text over my mesh. ...