Predefine attachment filename via REST API Upload


I am trying to predefine the name of the attachment i am about to upload with this code:

<form method="put" action='/rest/wikis/xwiki/spaces/Sandbox/pages/WebHome/attachments/test.txt' enctype="multipart/form-data">
<input type="file" name="filepath" />
<input type="submit" />

But I am getting “Method Not Allowed: The method specified in the request is not allowed for the resource identified by the request URI” by using the action parameter mentioned above. It is working without “test.txt” (action="/rest/wikis/xwiki/spaces/Sandbox/pages/WebHome/attachments" ), but the filename is kept.

Can somebody help me with that? Thanks in advance!


{{html clean="false"}}
<script type="text/javascript">
var upload = null;
function uploadFile()
var file = document.getElementById("fileA").files[0];
var formData = new FormData();
upload = new XMLHttpRequest();
//Fügt dem formData Objekt unser File Objekt hinzu
formData.append("datei", file);"PUT", "/rest/wikis/xwiki/spaces/Sandbox/spaces/Upload/pages/WebHome/attachments/Test12345.txt");upload.send(formData);
<form action="" method="post" enctype="multipart/form-data">
<input name="file" type="file" id="fileA" onchange="uploadFile();"/>
<input name="upload" value="Upload" type="button" onclick="uploadFile();" />