Replies: 2 comments 1 reply
-
hi @unkindee You should be able to do this quite easily with the useRequestPreSend hook. import React from "react";
import Uploady, { useRequestPreSend } from "@rpldy/uploady";
import UploadButton from "@rpldy/upload-button";
const getUrlForUpload = async (options) => {
const importantParam = await Promise.resolve(Math.floor(Math.random() * 3));
return importantParam > 0
? options.destination.url + `/item/${importantParam}`
: null;
};
const UploadWithDynamicUrl = () => {
useRequestPreSend(async ({ items, options }) => {
const newUrl = await getUrlForUpload(options);
return newUrl
? //set the new URL for this upload
{ options: { destination: { url: newUrl } } }
: //not valid URL, cancel the upload
false;
});
return <UploadButton />;
};
const MyApp = () => (
<Uploady
destination={{ url: "https://made-up-server/upload" }}
>
<UploadWithDynamicUrl />
</Uploady>
); The code above generates a random number and for
The updated URL will be: Working example can be found in this sandbox. |
Beta Was this translation helpful? Give feedback.
-
@unkindee A few questions/comments:
It would be really useful if you could create a minimal working example sandbox that I could follow the flow and your requirements better so I can help with this. |
Beta Was this translation helpful? Give feedback.
-
I have the following flow using react/redux:
example:
Step1: upload file1, file2, file3, and keep them pending
Step2: I get the ids from backend and I want to upload the files to url/id1 for file1, url/id2 for file2, url/id3 for file3 and possible other custom params
I have seen processPending and useRequestPreSend but I didn't find a way to upload only a certain file/batch out of multiple, is that possible?
Beta Was this translation helpful? Give feedback.
All reactions