html code:
<h1>Uploading a photo.</h1>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js"></script>
<script type="text/javascript">
var p;
var canvas = document.createElement("canvas");
var img1=document.createElement("img");
function converttobyte()
{
p=document.getElementById("file").value;
img1.setAttribute('src', p);
canvas.width = img1.width;
canvas.height = img1.height;
var ctx = canvas.getContext("2d");
ctx.drawImage(img1, 0, 0);
var dataURL = canvas.toDataURL("image/png");
alert("from getbase64 function"+dataURL );
return dataURL;
}
</script>
<form action="UploadFile" method="post" accept-charset="utf-8" name="UploadFileForm"
enctype="multipart/form-data">
<input type="file" id="file" name=""><br>
<input type="submit" value="Upload" onclick="converttobyte">
</form>
Python code:
def UploadFile(request):
if request.method == 'POST':
converttobyte = request.GET['converttobyte'].decode("base64")
#file = request.FILES['avatar']
default_storage.save("%s"%(converttobyte), ContentFile(converttobyte.read()))
return HttpResponse("File uploaded successfully")
else:
return HttpResponse("please upload a file")
what should be a statement that should be added after if request.method== 'post' in order to accept the the function return value in python script.
Please help me. Thanks in advance