Hi There,
I am trying to upload a file to my B4J App from an HTML page. I am using Jquery Ajax to send the file:
I have set up my server handler to take /upload and run to an upload module
The problem is my uploaded file then always has the HTTP header content in it
How do I get the file without the HTTP headers included?
I am trying to upload a file to my B4J App from an HTML page. I am using Jquery Ajax to send the file:
JS AJAX:
$('input[type=file]').on('change', prepareUpload);
function prepareUpload(event){
files = event.target.files;
};
$('#submitFile').click(function()
{
var formData = new FormData();
$.each(files,function(key, value){
formData.append(key, value);
});
var fileName = $('#sptDocUpload').val();
var fileCleaned = fileName.split('\\');
var docName = encodeURIComponent(fileCleaned[2]);
///console.log(docName);
console.log(files[0])
//alert(formData);
$.ajax({
url: 'upload?name='+docName,
type: 'POST',
data: formData,
success: function(data){ $('#whereyoutype').val(data); },
cache: false,
contentType: false,
processData: false
});
});
I have set up my server handler to take /upload and run to an upload module
Sub Handle from upload module:
Sub Handle(req As ServletRequest, resp As ServletResponse)
resp.Write("File Submitted. ")
If req.Method <> "POST" Then
resp.SendError(500, "method not supported.")
Return
End If
Dim In As InputStream = req.InputStream
Dim fileDir As String = File.DirApp & "\www\" & Main.filesFolder & "\"
Dim uploadedFile As InputStream = map.Get("name")
' Release Unix / Remove the comment on the line below to create a release application
fileDir = fileDir.Replace ("\", "/")
If File.Exists(fileDir, "") = False Then
File.MakeDir(fileDir,"")
End If
Dim out As OutputStream = File.OpenOutput(fileDir, name, False)
File.Copy2(In, out)
out.Close
Log("Received file: " & name & ", size=" & File.Size(Main.filesFolder, name))
resp.Write("File received successfully.")
End Sub
The problem is my uploaded file then always has the HTTP header content in it
How do I get the file without the HTTP headers included?