Hi,
I'm having some problems when using the Url plugin and then, manually, adding a file and uploading it.
This is the code. (I'm not adding some configuration for the rest of the plugins).
var uppy = Uppy.Core({ ... })
.use(Uppy.StatusBar, {...})
.use(Uppy.Transloadit, { ... })
.use(Uppy.Url, { host: 'https://api2.transloadit.com/uppy-server' })
.run()
After that, I would do:
uppy.addFile(url) // url is a string here
uppy.upload
But that will give me an error because it will reach for the normal addFile method for actual files, not urls. This is the error:
Uncaught (in promise) TypeError: Cannot read property 'slice' of undefined
at Object.getFileType (uppy.js:13343)
at uppy.js:11985
at <anonymous>
To make it work, I did this (which is kind of ugly but it works):
this.uppy.plugins.acquirer[0].addFile(url);
this.uppy.upload;
That way it will use the right method and the file is uploaded just fine.
This is my first time using both Transloadit and Uppy, so I'm sorry if I've missed something and that caused the error 馃槄
EDIT: I forgot to mention we are using the version v0.23.1
Hi. So yeah, there鈥檚 no official documented way in Uppy to add remote files via API. uppy.addFile(file) was intended for local files, but it is used internally for remote too. However, the shape of the file object is constructed by remote plugins, for Url it鈥檚 this:
So before calling addFile it fetches meta data, like size, via Uppy Server, adds the Uppy Server鈥檚 endpoint, and then uses all that to add the file.
Long story short, for now you can do it the way you鈥檝e described, but with getPlugin for a little less hacky solution:
uppy.getPlugin('Url').addFile(url)
uppy.upload()
The right thing to do would be to also wait for addFile promise, but it seems to me its not being returned, we鈥檒l try to fix in the next patch.
@arturi great, I'll do that, thanks!
it would be great if this was added to the docs, found myself needing this exact solution.
uppy.getPlugin('Url').addFile(response.url).then(function() {
uppy.upload();
});
^ worked perfectly
@cybersholt added to the docs, thank you!