Directuploadwillstorefilewithxhr没有开火

发布于 2025-02-05 03:59:06 字数 1059 浏览 2 评论 0原文

ECS类上使用Rails ActivEstorage,

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

function createDirectUpload(file, source, controller) {
  return new DirectUpload(file, source.url, source.token, source.attachmentName, controller);
}

我正在构造函数中的

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();
}

当我调用start时,我会创建一个新的DirectUpload,它可以按预期工作,但是Rownback DirectuploadwillStoreFileWithXhr并未触发。

I am using rails activestorage on a ecs class

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

function createDirectUpload(file, source, controller) {
  return new DirectUpload(file, source.url, source.token, source.attachmentName, controller);
}

In my constructor I create a new DirectUpload

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();
}

When I call start it works as expected, but the callback directUploadWillStoreFileWithXHR is not triggering.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酒绊 2025-02-12 03:59:07

如果需要跟踪文件上传的进度,则可以将第三个参数传递到DirectUpload constructor new DirectUpload(file,source.url,this)

,然后将其作为第五参数

>返回new directupload(file,source.url ,

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

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

If you need to track the progress of the file upload, you can pass a third parameter to the DirectUpload constructor new DirectUpload(file, source.url, this)

And you pass it as a fifth parameter return new DirectUpload(file, source.url, source.token, source.attachmentName, controller);

You initialiser should look like this:

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文