Archived

This topic is now archived and is closed to further replies.

@ndry

Add file troubles

Recommended Posts

Hi, im trying to create simple WebUI form that sends file to uTorrent.

Code (file add.html, that locates in webui.zip):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Add Remote Torrent</title><link href="./images/ut_small.png" rel="icon" type="image/png" /></head><body>
<!-- /* Torrent Add Dialog -->
<form action="./?action=add-file" method="post" enctype="multipart/form-data">
Torrent file:
<input type="file" id="dlgAdd-file" name="torrent_file" />

<fieldset style="display:none;">
<label for="dlgAdd-basePath">Path:</label> <select id="dlgAdd-basePath">
<option value="0">Default download directory</option>
</select>

<label for="dlgAdd-subPath">Sub-path:</label>
<input type="text" id="dlgAdd-subPath" />
</fieldset>

<input type="submit" value="Add Torrent" />
</form>
<!-- Torrent Add Dialog */ -->
</body></html>

But it only return is "invalid request". Can you help me to solve this problem?

P.S.: Im installed Safari Download Manager and Safari Upload Enabler on my iPad, it allows me to download .torrent file from any torrent tracer (even private) and add it to downloads manualy. It would be great to have program that catches .torrent downloads and sends it to webui automaticaly.

Share this post


Link to post
Share on other sites

Thanks, final code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Add Remote Torrent</title><link href="./images/ut_small.png" rel="icon" type="image/png" /></head><body>
<iframe src="token.html" id="tokenframe" width="100" height="100"></iframe>
<script language="javascript">
var token = "";
function getToken() {
document.getElementById("tokenframe").contentWindow.location.reload();
try
{
token = document.getElementById("tokenframe").contentWindow.document.getElementById("token").innerHTML;
}
catch(e)
{
token = "error";
}
}

function addToken() {
getToken();
document.getElementById("addFileForm").action += token;
}
</script>

<!-- /* Torrent Add Dialog -->
<form id="addFileForm" action="./?action=add-file&token=" onsubmit="addToken();" method="post" enctype="multipart/form-data">
Torrent file:
<input type="file" id="dlgAdd-file" name="torrent_file" multiple="multiple" />

<fieldset style="display:none;">
<label for="dlgAdd-basePath">Path:</label>
<select id="dlgAdd-basePath">
<option value="0">Default download directory</option>
</select>

<label for="dlgAdd-subPath">Sub-path:</label>
<input type="text" id="dlgAdd-subPath" />
</fieldset>

<input type="submit" value="Add Torrent" />
</form>
<!-- Torrent Add Dialog */ -->
</body></html>

Share this post


Link to post
Share on other sites

Excellent :)

I actually posted something very similar a few years ago, but didn't bother to allow it to be kept in an arbitrary filename (too lazy). This actually works out much more nicely in that regard.

Minor suggestion: if you don't want to require a user to press back to upload another torrent, it might be worth it to have the form target another iframe.

Share this post


Link to post
Share on other sites