Directuploadwillstorefilewithxhr没有开火
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果需要跟踪文件上传的进度,则可以将第三个参数传递到DirectUpload constructor
new DirectUpload(file,source.url,this)
,然后将其作为第五参数
>返回new directupload(file,source.url ,
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: