Uppy: Uploading multiple files to multiple endpoints

Created on 21 Aug 2019  路  8Comments  路  Source: transloadit/uppy

I have not yet found a way to use the XHRUpload plugin with multiple files where each file has it's own endpoint. The docs say that endpoint can only be one string. I understand that I could create multiple instances, but is that the way to go?

What I want to do is add an array of files and specify the endpoint for each. Is this possible?

Feature

Most helpful comment

Thanks for that example. We should provide an official API for it. At the moment, you can do something like the below.

The XHRUpload plugin reads option overrides from the file.xhrUpload property if it exists. This is not documented but is not going to be removed in a non-major release because we depend on it in the S3 plugin.

const file = uppy.getFile(fileID)
uppy.setFileState(fileID, {
  xhrUpload: {
    ...file.xhrUpload,
    endpoint: `https://endpoint/?filename=${encodeURIComponent(file.meta.name)}`
  }
})

You could do this for each file as it is added in an uppy.on('file-added') event listener, or do it just before an upload starts using uppy.on('upload', () => {}) and loop through all files uppy.getFiles().

All 8 comments

Hi! No, it鈥檚 currently not supported. I guess you are right and the way to do it would be to create multiple Uppy instances.

Okay, thank you arturi.

Could you please describe your use case, so we have more data to reason with? Why does each file need a separate endpoint in your setup.

Hey @arturi , sorry for the delayed reply.

We have data which, logically, belongs together and a failed upload in either part is considered to be a failure state. We are generating upload urls for each particular upload beforehand, but we want to handle all uploads "as one", that means, if one fails, it should retry, we want to use the automatic timeouts etc.

As it stands, we cannot use any of the "advanced" features of uppy because we can only upload one file to one url. We have written some business logic beforehand to handle it and were hoping to get rid of it by using uppy.

Creating multiple instances yields the same problem, it won't handle retries etc and/or we would have to glue the logic of multiple instances together (retry if one failed, max num of uploads etc)

Does that make it clearer/help?

Sorry that doesn't make it a whole lot clearer. Why can't you use, say, example.com/files/ as an upload endpoint and tag files with meta data so you're backend knows which files belong together?

I have same need. Zendesk attachments API (https://developer.zendesk.com/rest_api/docs/support/attachments) assumes that:
Endpoint is in form: https://{subdomain}.zendesk.com/api/v2/uploads.json?filename=myfile.dat&token={optional_token}
If user uploads multiple files, then

  • filename must be different
  • After first successful upload, I can get token from response which is needed to append to next uploads.

Any possibility to solve this with Uppy?

Thanks for that example. We should provide an official API for it. At the moment, you can do something like the below.

The XHRUpload plugin reads option overrides from the file.xhrUpload property if it exists. This is not documented but is not going to be removed in a non-major release because we depend on it in the S3 plugin.

const file = uppy.getFile(fileID)
uppy.setFileState(fileID, {
  xhrUpload: {
    ...file.xhrUpload,
    endpoint: `https://endpoint/?filename=${encodeURIComponent(file.meta.name)}`
  }
})

You could do this for each file as it is added in an uppy.on('file-added') event listener, or do it just before an upload starts using uppy.on('upload', () => {}) and loop through all files uppy.getFiles().

I am trying to do something similar with MUX Signed URLs. I would simply ask my backend to create an asset in MUX that responds with a unique endpoint for a particular file. I would then post the data to the unique URL.

I wonder if this is supported using Tus plugin and also if using XHR upload as mentioned in the previous comment still allows the use of Dashboard. Dashboard is <3

Was this page helpful?
0 / 5 - 0 ratings