Predefine attachment filename via REST API Upload

Hi,

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

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

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!

Solved:

{{velocity}}
{{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();
if(!file)
return;
//Fügt dem formData Objekt unser File Objekt hinzu
formData.append("datei", file);
upload.open("PUT", "/rest/wikis/xwiki/spaces/Sandbox/spaces/Upload/pages/WebHome/attachments/Test12345.txt");upload.send(formData);
}
</script>
<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();" />
</form>
{{/html}}
{{/velocity}}