Tim Posted August 7, 2017 Share Posted August 7, 2017 Hello, I currently use code such as the following in a TUniHtmlFrame to send binary file data from the browser to the server: function onFileLoadEnd(aEvent) { var fileContent = new Uint8Array(aEvent.target.result); var httpRequest = new XMLHttpRequest(); httpRequest.open('POST', gv_UploadUrl); httpRequest.setRequestHeader('Content-Type', 'application/octet-stream'); httpRequest.send(fileContent); } This works, but has the following disadvantages: Prior to running this code, I set gv_UploadUrl to a value obtained from UniSession.CallbackUrl(...MainForm()...). When onFileLoadEnd is called, it then triggers the OnAjaxEvent of the project's main form. I would prefer it to trigger the OnAjaxEvent of the TUniHtmlFrame instead. Handling the event in this way seems to be prone to the __BASE64__ Ajax Error that i mentioned in a previous post. I did move all of the data processing from the OnAjaxEvent handler to a background thread, and this certainly reduces the occurrence of the __BASE64__ Ajax Error, but it still happens occasionally Is there a way to transmit binary data from the browser to the OnAjaxEvent of a TUniHtmlFrame? Elsewhere in the code i am able to use the function ajaxRequest in Javascript to trigger the OnAjaxEvent of a TUniHtmlFrame and attach text-based data to it in the third parameter: function handleFiles(aFiles) { var params = []; for (var i = 0, f; f = aFiles[i]; i++) { gv_MaxFileID = gv_MaxFileID + 1; f.FileID = gv_MaxFileID; f.ToBeDeleted = false; gv_ListOfFiles.push(f); params.push("filename" + i + "=" + f.name); params.push("fileID" + i + "=" + f.FileID); params.push("filesize" + i + "=" + f.size); params.push("filetype" + i + "=" + f.type); } ajaxRequest(frmWizardFrame_DragDropFileUploader.hfrCode, "filesdropped", params); } But it's not clear to me how i could send binary data. Of course, i could base-64 encode the binary data and then send it as text, but that makes it 33% bigger. Alternatively, is there some version of UniSession.CallbackUrl that returns a URL that triggers the OnAjaxEvent of a given TUniHtmlFrame, rather than a form? Then i could continue using my existing code with XMLHttpRequest. Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now