Quantcast
Channel: NAV Three Tier — mibuso.com
Viewing all articles
Browse latest Browse all 10032

Download File From NAV Client, into SERVER.

$
0
0
Hello m8ts, So this is my first post and I hope I'm not duplicating it. I've tried countless times to look internet for a solution (None was fully compatible whatsoever).

I have to create a tool wich first thing it needs to do is download a GZ file from an URL, but I'm not able to find the solution in any place.

I've found 2 so far:

1 - Using ADOStream:

URLINDEX := 'SOME URL';

IF(ISCLEAR(MXH)) THEN
CREATE(MXH,FALSE,TRUE);
MXH.open('GET',URLINDEX,FALSE);
MXH.send('');

IF MXH.status <> 200 THEN BEGIN
MESSAGE('ERROR');//TEST MESSAGE
CurrReport.BREAK;
END;

FileName := MXH.getResponseHeader('Content-Disposition');

IF STRPOS(FileName,'filename=') = 0 THEN
FileName :=''
ELSE BEGIN
FileName := COPYSTR(FileName,STRPOS(FileName,'filename=') + 10);

IF ISCLEAR(ADOStream) THEN
CREATE(ADOStream,FALSE,TRUE);

ADOStream.Type := 1;
ADOStream.Open;
ADOStream.Write(MXH.responseBody);

// ---> This line is commented from the online code found, because It wouldn't pass through here It would always close the stream. The url inputted is correct, and returns a download file if opened on a Browser.
//IF ADOStream.State = 1 THEN
//ADOStream.Close;

FileName := FICHEROS + FileName;
MESSAGE(FILENAME);
//CODE BREAKS HERE, IN SAVE FILE
ADOStream.SaveToFile(FileName,2);

//CURREPORT.BREAK;
ADOStream.Close;
END;

EDIT: Variables:
MXH Automation 'Microsoft XML, v6.0'.XMLHTTP60
ADOSTREAM Automation 'Microsoft ActiveX Data Objects 2.8 Library'.Stream
FILESYSTEM Automation 'Windows Script Host Object Model'.FileSystemObject
FILENAME Text
FILEPATH Text

This will only execute "Error when writing to the file.". And as told URL and Locations are fine.


2 - Using InStream / OutStream.

URLINDEX := 'some url';

IF(ISCLEAR(MXH)) THEN
CREATE(MXH,FALSE,TRUE);
MXH.open('GET',URLINDEX,FALSE);
MXH.send();

IF MXH.status <> 200 THEN
MESSAGE('ERROR URL'); //MESSAGE FOR TESTING

FICHERO.CREATE(FICHEROS+'index_0.gz');
FICHERO.CREATEOUTSTREAM(ONS);
INS := MXH.responseStream;
COPYSTREAM(ONS,INS);
FICHERO.CLOSE;

EDIT:Variables
FICHERO File
MXH Automation 'Microsoft XML, v6.0'.XMLHTTP60
INS InStream
ONS OutStream

This won't work, he's not able to transform Automation on InStream.

Those codes, are from the internet modified (not mine) to get to do what I need.

Working under NAV 2016. Also tried a CodeUnit from a WebPage wich is suposed to download files (http://www.dynamics.is/?attachment_id=584), also unusable for our systems.

This thing is driving me so crazy I might end with 4 JaggerMeister bottles under a bridge hallucinating with nav streams.

Thank you very much,

Viewing all articles
Browse latest Browse all 10032

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>