How to set Content Disposition?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to set Content Disposition?

1,122 Views
shreyas_s
Contributor I

I am working on MQX 4.1, in this for some application i want to export .xml
file for the user,

For this Content Type set as "application/octet-stream", with these
settings Internet Explorer is opening .xml file directly without providing save
as option (Mozilla and Chrome Providing Save as Option).

For this additionally need to Content Disposition as "attachment"
so that IE will provide save as option.

Can anyone please guide how and where to set Content Disposition?

Labels (1)
0 Kudos
Reply
3 Replies

666 Views
soledad
NXP Employee
NXP Employee

Hi,

I just reviewed the source code for the web_hvac demo in MQX 4.0.2. I can see that the USB file system possibility is still here. You can see that http_aliases array is actually used to define the other file system where the web server can find other files:

#if DEMOCFG_ENABLE_WEBSERVER
HTTPSRV_ALIAS http_aliases[] = {
    {"/usb/", "c:\\ (file:///c://)"},
    {NULL, NULL}
    };
#endif
You also can see that this is used as one of the parameters for the creation of the web server:
params.alias_tbl = (HTTPSRV_ALIAS*)http_aliases;
You can access to those files by adding /usb/ to the end of the ip address in the web browser; just like this:
http: //192.168.1.202/usb/index.html

Using this feature I think you can get the access to the content.


Have a great day,
Regards
Sol
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply

666 Views
shreyas_s
Contributor I

Hi Sol,

Thanks for the Information....

Problem is I am not facing issue regarding file access...

Main issue is insted of save as option, .xml file is getting open in Internet Exlorer itself...

For this we need to set Contenet Disposition.....

I need help about how and where we can set content disposition?

Thanks for the help,

Shreyas

0 Kudos
Reply

666 Views
karelm_
Contributor IV

Hi,

If you need to add/modify any MIME type in HTTPSRV you have to do following:

  1. Open file httpsrv.h located in %MQX_ROOT%\rtcs\source\include.
  2. Find MIME type definition (typedef enum httpsrv_content_type).
  3. Add new MIME type HTTPSRV_CONTENT_TYPE_XML like this:
    • typedef enum httpsrv_content_type

      {

          HTTPSRV_CONTENT_TYPE_OCTETSTREAM = 1,

          HTTPSRV_CONTENT_TYPE_PLAIN,

          HTTPSRV_CONTENT_TYPE_HTML,

          HTTPSRV_CONTENT_TYPE_CSS,

          HTTPSRV_CONTENT_TYPE_GIF,

          HTTPSRV_CONTENT_TYPE_JPG,

          HTTPSRV_CONTENT_TYPE_PNG,

          HTTPSRV_CONTENT_TYPE_SVG,

          HTTPSRV_CONTENT_TYPE_JS,

          HTTPSRV_CONTENT_TYPE_ZIP,

          HTTPSRV_CONTENT_TYPE_PDF,

           HTTPSRV_CONTENT_TYPE_XML,

      } HTTPSRV_CONTENT_TYPE;

  4. Open file httpsrv_supp.c located in %MQX_ROOT%\rtcs\source\apps.
  5. Find MIME type string definition table (static const httpsrv_table_row content_type[]).
  6. Add your MIME type. For XML file a line you should add will look like this:
    • static const httpsrv_table_row content_type[] = {

              { HTTPSRV_CONTENT_TYPE_PLAIN,       "text/plain" },

              { HTTPSRV_CONTENT_TYPE_HTML,        "text/html" },

              { HTTPSRV_CONTENT_TYPE_CSS,         "text/css" },

              { HTTPSRV_CONTENT_TYPE_GIF,         "image/gif" },

              { HTTPSRV_CONTENT_TYPE_JPG,         "image/jpeg" },

              { HTTPSRV_CONTENT_TYPE_PNG,         "image/png" },

              { HTTPSRV_CONTENT_TYPE_SVG,         "image/svg+xml"},

              { HTTPSRV_CONTENT_TYPE_JS,          "application/javascript" },

              { HTTPSRV_CONTENT_TYPE_ZIP,         "application/zip" },

              { HTTPSRV_CONTENT_TYPE_XML,         "application/xml" },

              { HTTPSRV_CONTENT_TYPE_PDF,         "application/pdf" },

              { HTTPSRV_CONTENT_TYPE_OCTETSTREAM, "application/octet-stream" },

              { 0,    0 }

      };

  7. Locate content table variable (static const httpsrv_content_table_row content_tbl[]).
  8. Add file extension for new MIME type like this:
    • static httpsrv_content_table_row content_tbl[] = {

          /* Size,          extension, MIME type,                        Cache? */

          {sizeof("js")-1 ,   "js",    HTTPSRV_CONTENT_TYPE_JS,          TRUE},

          {sizeof("css")-1,   "css",   HTTPSRV_CONTENT_TYPE_CSS,         TRUE},

          {sizeof("gif")-1,   "gif",   HTTPSRV_CONTENT_TYPE_GIF,         TRUE},

          {sizeof("htm")-1,   "htm",   HTTPSRV_CONTENT_TYPE_HTML,        TRUE},

          {sizeof("jpg")-1,   "jpg",   HTTPSRV_CONTENT_TYPE_JPG,         TRUE},

          {sizeof("pdf")-1,   "pdf",   HTTPSRV_CONTENT_TYPE_PDF,         FALSE},

          {sizeof("png")-1,   "png",   HTTPSRV_CONTENT_TYPE_PNG,         TRUE},

          {sizeof("svg")-1,   "svg",   HTTPSRV_CONTENT_TYPE_SVG,         TRUE},

          {sizeof("txt")-1,   "txt",   HTTPSRV_CONTENT_TYPE_PLAIN,       FALSE},

          {sizeof("xml")-1,   "xml",   HTTPSRV_CONTENT_TYPE_XML,         FALSE},

          {sizeof("zip")-1,   "zip",   HTTPSRV_CONTENT_TYPE_ZIP,         FALSE},

          {sizeof("html")-1,  "html",  HTTPSRV_CONTENT_TYPE_HTML,        TRUE},

          {sizeof("shtm")-1,  "shtm",  HTTPSRV_CONTENT_TYPE_HTML,        FALSE},

          {sizeof("shtml")-1, "shtml", HTTPSRV_CONTENT_TYPE_HTML,        FALSE},

          /* Following row MUST have length set to zero so we have proper array termination */

          {0,                      "", HTTPSRV_CONTENT_TYPE_OCTETSTREAM, FALSE}

      };

  9. Recompile RTCS and your application.


0 Kudos
Reply