#1 2022-04-08 09:49:19

squirrel
Member
Registered: 2015-08-13
Posts: 155

Setting content-type when returning blob

I am attempting to correctly set the content-type when sending parts of binary files using code like this:

        AddToCSV('Accept-Ranges: bytes', Ctxt.Call.OutHead, #13#10);
        AddToCSV('Content-Range: bytes '+ inttostr(RangeStart) +'-'+inttostr(RangeEnd)+'/'+inttostr(SrcFileSize), Ctxt.Call.OutHead, #13#10);
        AddToCSV(GetMimeContentTypeHeader('',SrcFileName), Ctxt.Call.OutHead, #13#10);
        Ctxt.ReturnBlob(blob, HTTP_PARTIALCONTENT);

In the procedure, the content-type is correctly set as video/H264 in the Ctxt.Call.OutHead, but when the header reaches the client, it is content-type: application/json; charset=UTF-8

Any suggestions where this might be overridden?  I have tried stepping through ReturnBlob, but when it returns to my proc, the header still looks correct, so I am not sure where it is happening.

Using v1.18

Offline

#2 2022-04-08 12:21:24

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: Setting content-type when returning blob

ReturnBlob() should already set the content type for you, from the blob binary content.
Yo have a FileName optional parameter to specify the source file name if needed:

 Ctxt.ReturnBlob(blob, HTTP_PARTIALCONTENT, true, SrcFileName);

Offline

#3 2022-04-08 12:33:42

squirrel
Member
Registered: 2015-08-13
Posts: 155

Re: Setting content-type when returning blob

It looks as if it always thinks the binary data is json, so maybe that is used as a fallback when it can't determine the data type?  Since these are partial files, not full files (which would be too big - up to 1 gb), I assume determining the content type will not succeed.  How can I provide / override / force the content type when serving binary data?

Providing the full path of the original file does not resolve the issue - is still sends the content-type as json.

Offline

#4 2022-04-08 12:37:40

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: Setting content-type when returning blob

Which HTTP server class do you use on mORMot?

Offline

#5 2022-04-08 12:38:13

squirrel
Member
Registered: 2015-08-13
Posts: 155

Re: Setting content-type when returning blob

TSQLRestServerFullMemory

Offline

#6 2022-04-09 04:51:31

igors233
Member
Registered: 2012-09-10
Posts: 241

Re: Setting content-type when returning blob

> How can I provide / override / force the content type when serving binary data?

Try with base Ctxt.Returns where you have full control, for example:
Returns(ResultVar.AsJSON, HTTP_SUCCESS, 'video/H264, True, True);

Last edited by igors233 (2022-04-09 04:52:13)

Offline

Board footer

Powered by FluxBB