Good afternoon team,
My team and I are working on a way to have users upload a txt, jpg, or pdf, like files onto our XenServer XCP. I came across your host plugin write up
http://blogs.citrix.com/2012/08/17/hello-xen-api-host-plugin/ , and saw that you mentioned something about uploading images.
Will it be possible for you to assist me? We have a simple html file in the /opt/xensource/www,
We then added a form, to allow users who browse to the ip address of the sever to upload a file to it.
___________________________________________________
Index.html
<form enctype="multipart/form-data" action="" name="save_file2.py" method="post" style="color:#454545;font-size:16px;font-weight:normal;text-align:left;margin:10px;">
Choose a file to upload: <input type="file" name="file"><br />
<input type="submit" value="Upload"></p>
</form>
___________________________________________________
Save_file.py
#!/usr/bin/env python
import cgi, os
import cgitb; cgitb.enable()
try: # Windows needs stdio set for binary mode.
import msvcrt
msvcrt.setmode (0, os.O_BINARY) # stdin = 0
msvcrt.setmode (1, os.O_BINARY) # stdout = 1
except ImportError:
pass
form = cgi.FieldStorage()
# A nested FieldStorage instance holds the file
fileitem = form['file']
# Test if the file was uploaded
if fileitem.filename:
# strip leading path from file name to avoid directory traversal attacks
fn = os.path.basename(fileitem.filename)
open('files/' + fn, 'wb').write(fileitem.file.read())
message = 'The file "' + fn + '" was uploaded successfully'
else:
message = 'No file was uploaded'
print """\
Content-Type: text/html\n
<html><body>
<p>%s</p>
</body></html>
""" % (message,)
___________________________________________________
Unfortunately, when I test out the html, it returns the below error:
![](pngD4XgaCfdFz.png)
Can you please help me to understand what is happening, and maybe I can finally get this upload process to work properly.
Thank you,
Agyeman B. Danso Jr.
Security Engineer
infoLock Technologies
877.610.5625 x253 - direct
ADanso@xxxxxxxxxxxxxxxx