Get file in IOS from a Delphi server

Hi,
I have a delphi server, and an IOS client.
There is a method where IOS client could ask a file to the server.

The delphi (server) part is like this :
function TWSYCatService.getFile(const fileName: AnsiString; const folder: AnsiString; out fileData: Binary; out fileSize: Int64): Boolean;
Var
fileStream: TFileStream;
res : boolean;
currentFolder : AnsiString;
Begin
res:= false;
Try
currentFolder := ExtractFilePath(ParamStr(0));
fileStream := TFileStream.Create(currentFolder + folder + ‘/’ + fileName, fmopenRead);
fileSize := fileStream.Size;
fileData := nil;
if fileSize > 0 then
begin
fileData := Binary.Create;
fileData.SetSize(fileSize);
fileData.CopyFrom(fileStream,0);
fileData.Position := 0;
End;
Finally
if (fileStream <> nil) then FreeAndNil(fileStream);
End;
result := res;
End;

The XCode part is like this :
-(BOOL) getFileFromServer:(id)args
{
NSString *fileName = [TiUtils stringValue:[args objectAtIndex:0]];
NSString *folder = [TiUtils stringValue:[args objectAtIndex:1]];
NSString *destFileName = [TiUtils stringValue:[args objectAtIndex:2]];
NSData stream;
int64
fileSize;
NSLog(@“Ask file to server”);
BOOL res = [MyService getFile:fileName :folder :&stream :fileSize];
NSLog(@“Size : @d”,fileSize);
NSLog(@“Length : @d”,[stream length]);
if (res) {
NSLog(@“Writing to file”);
res = [stream writeToFile:destFileName atomically:YES];
}
return res;
}

the app crash when calling getFile. No problem on server side.
other web service methods are called without any problem.

Any idea ?

Regards

Hello Armindo,

Your code looks ok, I have even created a test case based on it, it works. You can find it attached, both client and server. So we need more details from you to help, such as:

  • RO and Xcode version used
  • the exact error displayed
  • getfile calls the _intf code, you could step into it with a debugger and find out which line is actually failing

Best regards - Sergey.

Hi Sergey,
thanks for your precious help.
Will test this and will come back to you.
Regards