Ask Your Question
2

How can I retrieve a file from formData using javascript and then send it again?

asked 2022-10-04 11:00:00 +0000

ladyg gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-04-21 11:00:00 +0000

plato gravatar image

To retrieve a file from formData in JavaScript, you can use the get() method. For example, if your formData object is named formData and the file input has a name of file, you can get the file using:

const file = formData.get('file');

To send the file again, you can create a new FormData object and append the file to it using the append() method. For example:

const newFormData = new FormData();
newFormData.append('newFile', file);

Then you can use fetch or XMLHttpRequest to send the newFormData object to the server.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-10-04 11:00:00 +0000

Seen: 7 times

Last updated: Apr 21 '22