-
|
My problem in a nutshell; I am using react uploady component to upload images. The problem I need to rename the files while uploading but I couldn't find a way to do it. I read all the documentation of react uploady and googled a lot but no luck. There are no relevant examples. There are examples how to rename file while uploading they don't work in this components logic. Could anyone can help me? https://stackoverflow.com/questions/76752328/renaming-filename-using-react-uploady |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 6 replies
-
|
You can do the renaming either on the server or on the client. On the client you can do it like so: useRequestPreSend(({ items, options }) => {
items[0].file.name = "new name";
return {
items
};
});If you want to grab the new name from the client and pass it as a param for your server to handle the rename, you can do it like so: useRequestPreSend(({ items, options }) => {
return {
options: {
params: {
newName: getNewName(items[0]),
}
}
};
});The "newName" param will be submitted along with the uploaded file and you can use it on the server to save the file (make sure to sanitize and validate, of course). In both cases, the hook to use is useRequestPreSend that allows you to make changes just before the request is sent.
|
Beta Was this translation helpful? Give feedback.
-
|
I am using the example you provided here https://react-uploady.org/docs/guides/AddRemoveThenUpload/ Unfortunately. useRequestPreSend not fired in the List component, either in uploady. How can I make it fire? |
Beta Was this translation helpful? Give feedback.
-
|
I forked the example and put the useRequestPreSend to UploadList function to change the name of file. It's fired but file name remained unchanged https://codesandbox.io/s/react-uploady-add-and-remove-before-upload-forked-3dc7yg |
Beta Was this translation helpful? Give feedback.
-
|
I don't know it's dissapeared. This time I tested useRequestPreSend is there. It does not change the file name. I thought file name is read only. https://codesandbox.io/s/react-uploady-add-and-remove-before-upload-forked-3dc7yg?file=/src/App.js |
Beta Was this translation helpful? Give feedback.
-
|
Yes, it's been called. I solved that. I was mistaken there. But my main problem is still there. I can't change file name before upload in the client. |
Beta Was this translation helpful? Give feedback.


so this is more a JS question than Uploady, but here's the way:
You actually need to create a new File object -