Home > Net >  Define header filename as variable in Arduino/C
Define header filename as variable in Arduino/C

Time:01-20

In arduino IDE i want to define a filename as variable. Then insert it into a header for uploading a file to a flask application as variable.

Filename should be as example: 1

Hardcoding the filename as following works well:

if (https.begin(*client, "https://hanspeter//")) {
    https.addHeader("Content-Type", "image/jpeg");
    https.addHeader("Content-Disposition", "inline; filename=\"1\"");

I tried different options to define a variable, but always get errors:

Option 1:

const char *thisisaname = "1";
https.addHeader("Content-Disposition", "inline; filename="thisisaname);

Error: unable to find string literal operator 'operator""thisisaname' with 'const char [18]', 'unsigned int' arguments

Option 2.

const char *thisisaname = "1";
https.addHeader("Content-Disposition", "inline; filename=\""   thisisaname   "\""));

Error: invalid operands of types 'const char [19]' and 'const char*' to binary 'operator '

Option 3.

const char *thisisaname = "\"1\"";
https.addHeader("Content-Disposition", "inline; filename="thisisaname);

Error: invalid operands of types 'const char [19]' and 'const char*' to binary 'operator '

CodePudding user response:

The normal way of doing that would be a #define. It is memory efficient and won't take up much flash. Then you can also take advantage of string literal concatenation:

#define SO "http://stackoverflow.com/"
#define URL "questions"
...
surf_to(SO URL)

which expands to surf_to("https://stackoverflow.com/questions")

  • Related