- This topic has 2 replies, 2 voices, and was last updated 5 years, 8 months ago by .
Viewing 2 reply threads
Viewing 2 reply threads
- You must be logged in to reply to this topic.
Hello
I use TkbmMWEventHTTPService as REST server for mobile application (on Android).
I put some images on server root folder and tried to get it from WEB browser. WEB browser doesn’t recognize result as binary file. How do I fill result for send file as it does usual HTTP WEB server?
I use this code
function TkbmMWHTTPService.kbmMWEventHTTPServiceGet(const Func: string; const ClientIdent: TkbmMWClientIdentity; const AURL: string;
Args: TkbmMWVariantList): Variant;
var
f: TFileStream;
s: TStringStream;
s1: String;
begin
f := nil;
s := nil;
try
try
s1 := ExtractFileDir(ParamStr(0)) + ‘\root’ + AURL;
if FileExists(s1) then
begin
f := TFileStream.Create(s1, fmOpenRead);
Result := StreamToVariant(f);
end
else
begin
s := TStringStream.Create;
s.WriteString(‘<h1>Mobile Waiter Server</h1>’);
s.WriteString(Format(‘Page %s not found’, [AURL]));
Result := StreamToVariant(s);
end;
finally
if f <> nil then
FreeAndNil(f);
if s <> nil then
FreeAndNil(s);
end;
except
end;
end;
Thanks
I’ve done it
I added Self.SetResponseMimeType(
f := TFileStream.Create(s1, fmOpenRead);
ext := UpperCase(ExtractFileExt(AURL));
if leftStr(ext, 1) = ‘.’ then
ext := copy(ext, 2, length(ext) – 1);
if ext = ‘APK’ then
Self.SetResponseMimeType(‘application/vnd.android.package-archive’)
else
Self.SetResponseMimeType(GetMimeTypeExt(ext));
Result := StreamToVariant(f);
Hi,
You can also add the mimetype for APK to the service definitions mimetype list.
Eg:
TkbmMWHTTPServiceDefinition(server.RegisterService...).MimeTypes.Values['APK']:=‘application/vnd.android.package-archive’;
Then you can simply use
Result:=self.HTTPResponseFromFile(yourAPKfilepath);
best regards
Kim/C4D