WebShop File Upload
Lee D Papworth
12-5-19
Lee D Papworth
12-5-19
I have a customer requirement to modify Webshop so files can be uploaded and attached to the Sales orders created through WebShop

Does StandardERPServer support html form based uploads?

Can this even be done?


I have tried many things but keep hitting brick walls.

Thanks

Lee
Kuda Chanengeta
12-6-19
Created byLee D Papworth08:52 5 Dec 2019
I have a customer requirement to modify Webshop so files can be uploaded and attached to the Sales orders created through WebShop Does StandardERPServer support html form based uploads? Can this even be done? I have tried many things but keep hitting
Hi Lee, I am looking at this issue and will get back to you as soon as possible.
Lee D Papworth
12-6-19
Created byKuda Chanengeta00:20 6 Dec 2019
Hi Lee, I am looking at this issue and will get back to you as soon as possible.
Thanks Kuda,

I eagerly await your reply

Regards

Lee
Lee D Papworth
12-9-19
Any news please Kuda?
Swati D.
12-10-19
Hi Lee

Can you please be more specific with your request as it is difficult to understand what you are trying to do

So kindly explain in much more detail

Many thanks

Swati 12.10
Lee D Papworth
12-10-19
Created bySwati D.20:31 10 Dec 2019
Hi Lee Can you please be more specific with your request as it is difficult to understand what you are trying to do So kindly explain in much more detail Many thanks Swati 12.10
Sorry I thought I had explained myself quite clearly.

With many web sites such as recruitment type companies you have the ability to locate a file on your computer and upload it to the host server. Typically in this example it would be a c.v

This is achieved usually with html, some javascript then a function running on the server.

I want to add this functionality to a webshop application I am developing.

I need to know if this can be done with StandardERP.

I have been looking at XMLHttpRequest, javascript but do not know how to write the server side hal code.


If you pass this onto someone technical they will know immediately what I am asking.


Many thanks in advance

Lee




Aldevinas Katkus
12-11-19
Created byLee D Papworth21:05 10 Dec 2019
Sorry I thought I had explained myself quite clearly. With many web sites such as recruitment type companies you have the ability to locate a file on your computer and upload it to the host server. Typically in this example it would be a c.v This is ach
There are some functions named "upload" in the source. I would look how file manager in mystandard works. I never did something like this before, so cannot tell you more.
Lee D Papworth
12-11-19
I have looked in WebNgUpload but cannot work out if this is what I need.

Really need some technical assistance as soon as possible please.

I am hoping someone in the StandardERP world can help me.

You have this feature in MyStandard when paying invoices it invites you to upload a file. I have searched hal code but the function is not there.


Help!

Thanks

Lee
Kuda Chanengeta
12-11-19
Hi Lee,

So we don't have that supported in standard at the moment so it would have to be customised.

You could start by taking a look at how we create attachments in general (e.g. when creating email from Invoice we create pdf attachment). Then the next step would be probably to create a similar function in HAL, and then when you submit the HTML form with uploaded file, we would call this function in HAL.


You could put through a wish for this as well as I am sure this would be good to have in the standard product version.

I hope this is useful and makes sense.
Lee D Papworth
12-11-19
Hi Kuda,

creating attachments in general is easy and we have been familiar with doing this in hal code for many years.

This issue is getting the file onto the server. Once it is on the server attaching it to whatever record I want is easy.

When you upload a file using HTML it requires some server side code to facilitate the upload.
Your function on Mystandard is /WebUpdatingAction.hal?action=hm_registerste

This is the type of function I need

Thanks

Edgars Dzenis
12-27-19
Hello, Lee

You might take a look at the procedure WebFileUpload. It uses primitive WebGetRawPostData which I think is what You are looking for.
Lee D Papworth
12-27-19
Hi Edgars,

I have tried using this but I get nowhere. Would anyone be able to provide some sample code?

Really desperate now as I cannot complete job.

Fingers crossed you can help me

Best regards

Lee
Edgars Dzenis
1-2-20
Hi,

This procedure will save posted file when called ip:webport/WebTEST.hal with file passed in it

global webpublic
updating procedure WebTEST()
begin
area a;

WebGetPostData(a);

WriteAreaToFile(a,"tmp/test.zip",0);


return;
end;
Lee D Papworth
1-2-20
Created byEdgars Dzenis13:37 2 Jan 2020
Hi, This procedure will save posted file when called ip:webport/WebTEST.hal with file passed in it global webpublic updating procedure WebTEST() begin area a; WebGetPostData(a); WriteAreaToFile(a,"tmp/test.zip",0); return; end;
Hi Edgars,

this only seems to save the posted web arguments and not the actual file.


I have already tried this method before logging it on the Forum.

Please come back to me

Regards

Lee







Edgars Dzenis
1-2-20
That's weird, did a POST call with file as a body and the file was saved on the server.
What SERP version are You using?
Lee D Papworth
1-2-20
Created byEdgars Dzenis15:02 2 Jan 2020
That's weird, did a POST call with file as a body and the file was saved on the server. What SERP version are You using?
Hi Edgars,

SERP 8.5 2019-09-15 build 85321026

Regards

Lee
Paul Timms
1-3-20
That would involve the end user making some kind of HTTP POST to the Hansa web server, which is all technically possible but probably quite hard to make simple for the end user.

The Issue Tracking part of this partner portal allows uploading of files. How does that work?
Lee D Papworth
1-3-20
Created byPaul Timms16:20 3 Jan 2020
That would involve the end user making some kind of HTTP POST to the Hansa web server, which is all technically possible but probably quite hard to make simple for the end user. The Issue Tracking part of this partner portal allows uploading of files. Ho
Paul,

I have been looking at that. It uses server sided javascript to call hal.

Snippet of code I lifted from the partner portal.

function FileUpload(wrap,filesinp,tag,id,callback)
{
this.started = false;
this.totfiles = 0;
this.donefiles = 0;

this.DouploadChunk = function(file,start,end,filesize, BYTES_PER_CHUNK,progress,sess,blob,callback){
var self = this;
var xhr = new XMLHttpRequest();
xhr.open('POST', "/WebFileUpload.hal?action=doupload&sess=" + sess + "&part=" + start +"&nocache="+new Date().getTime(), true);
xhr.upload.onprogress = function (e) {

};
xhr.onloadend = function (e) {
};
var blob = file.slice(start,end);



Could really do with some guidance on this. I have mentioned Xhr in this thread already but no one took it further

Lee
Edgars Dzenis
1-9-20
Hi, Lee,

So this part WebFileUpload.hal?action=doupload you can see in the procedure WebFileUpload.
The DoUploadChuck is roughly like this(it's not actual code and won't work, it's just to look at roughly how it works. Hope it helps)

global
function Boolean webup(var string filename,var area rfilearea)

begin
Area FileArea,img,FADone,nFileArea;
Longint enter;
Longint lcnt,pos,spos,epos,pepos;
string 255 tstr,namestr;
boolean getnamef;
Longint namepos,nameepos,i;
string 255 link;
boolean savef;

getnamef = false;
namepos = 0;
nameepos = 0;

savef = true;
WebGetRawPostData(rFileArea);
//ReplaceWebStrings(nFileArea,rfilearea);

savef = true;


webup = savef;
return;
end;


global
updating procedure chunkup(string sess,string fn,var string nename)
begin

CreateFolder("tmp/" & sess);
CreateFile("tmp/" & sess & "/" & fn & ".tmp");
nename = fn & ".tmp";


return;
end;

global

updating procedure chunkupchunk(string sess,string fn,var area tarea)
begin

AppendAreaToFile("tmp/" & sess & "/" & fn,tarea);

return;
end;


global
updating procedure chunkupfinish(string sess,string tmpname,string fn)
begin
string 255 folder;

folder = "tmp/" & sess;
RenameFile(folder & "/" & tmpname,folder & "/" & fn);

return;
end;

global
procedure HandleFileUploadFinish(string sess)
begin
string 255 path,filename,id,tag;


switch (tag) begin
case "test":
if (FileExists("tmp/" & tag & "/" & sess)) then begin
RenameFile("tmp/" & tag & "/" & sess,"tmp/" & tag & "/" & filename);
end;
end;


path = "tmp/" & tag & "/" & sess;
if (FileExists(path)) then begin
Delete_File(path);
end;

return;
end;

global
procedure WebDoUploadChunk()
begin
string 255 filename,foldername,tname;
String 255 server_uuid,server_addr,server_port,country,product,localizations;
Integer oldcomp,cc;

area tarea;
record CUVc CUr;
BOolean succf;

switch (WebGetArg("type")) begin
case "start":
qupdating.chunkup(GetWebSessionUUID,WebGetArg("filename"),filename);
PutSessionString("temp_upload_filename",filename);
PutSessionString("temp_upload_filename2",WebGetArg("filename"));
case "file":
webup(tname,tarea);
qupdating.chunkupchunk(GetWebSessionUUID,GetSessionString("temp_upload_filename"),tarea);
case "end":
qupdating.chunkupfinish(GetWebSessionUUID,GetSessionString("temp_upload_filename"),GetSessionString("temp_upload_filename2"));
product = "test";


foldername = "tmp/" & GetWebSessionUUID;
WebOutString("");
end;

return;
end;
Lee D Papworth
1-10-20
Created byEdgars Dzenis13:08 9 Jan 2020
Hi, Lee, So this part WebFileUpload.hal?action=doupload you can see in the procedure WebFileUpload. The DoUploadChuck is roughly like this(it's not actual code and won't work, it's just to look at roughly how it works. Hope it helps) global function Boo
Thank you Edgars.

I kind of follow the logic. However one thing that baffles me is how does switch (WebGetArg("type"))

change from Start > File > End ?

This is what I assumed some XHR script would be sending to the Hansa server.

In your example it is all Hal code so I am a bit lost how each stage gets invoked.

Please come back to me

Thanks

Lee


Nejc R.
1-14-20
Hello,

This example is used with XHR for asynchronous upload.

The "start" part is just to receive the filename and create the file, setup session, setup loading bar on the webpage etc. It's just a normal ajax call to the server to make sure everything is set up.
$.get("/WebFileUpload.hal?action=start&session=" + session + "&newname=" + newname + "&filename=" + filename,function(data){...});

"file" is the only place where XHR is actually used. The way this is setup it can handle breaking up larger files and uploading them as parts
if you want the upload to actually work in blocks you need to handle breaking the file apart in JavaScript and send piece by piece with XHR, the server-side code will just append everything it gets to the file.
xhr.open('POST', "/WebFileUpload.hal?action=file&session=" + session + "&tmpname=" + tmpname +"&fn=" & fn, true);

"end" is also just a standard ajax call to finalize upload, move file to proper location, delete the temporary one and clean up the loading bar on the webpage.
$.get("/WebFileUpload.hal?action= end&session=" + session,function(data){...});


Dejan R.
1-20-20
Hello Lee,

Was Nejc's reply helpful?
Lee D Papworth
1-22-20
Created byDejan R.14:11 20 Jan 2020
Hello Lee, Was Nejc's reply helpful?
Hello Dejan,

it is a start thank you. I will try asap to put this together and feedback on here my successes and/or failures


Thanks

Lee
Dejan R.
1-23-20
Ok, thank you. We are hopping for positive feedback ;)
Zilvinas Suliauskas
5-5-20
Hello Lee,

Could you please confirm if it worked for you or not?
Other partners would like to know it as well.
Lee D Papworth
5-5-20
Hi Zilvinas

I couldn't get this to work. In the end I had to come up with another solution.

I encode the image using html and JavaScript utilising readAsDataURL then upload to the server.

Once there I use the hal primitive AreaBase64Decode to translate it back into an image file and attach it to the record

fname = "tmp/" & uploadfilename;
AreaBase64Decode(wArea,wImageArea);
WriteAreaToFile(wImageArea,fname,0);

RecordLinkFile(fname,0,PRr,CurrentCompany);


Regards

Lee
Zilvinas Suliauskas
5-5-20
Thank you for letting us know :)
Leave Comment
You can subscribe to notifications for this post by selecting the 'star' icon on the top right corner of the post.
Back to the list
Latest Posts
Reino Botha
Please check your version of android if it is the same as the server you are connecting too. ...
08:24 21 Nov 2024
Bror-Erik Kotiranta
In NC you hace operations>>ai chats. They are used for these Br, Bror-Erik...
05:12 21 Nov 2024