HELP! dfx cmd call with txt file

I have a txt file, and i want to pass that text from file to dfx command. How can i do that? Please help me with the syntax.
say text file : base64.txt and
DFX cmd : dfx canister call token setLogo ‘(“Text from text file , i want to pass”)’ .

I’m not sure if it works, maybe dfx deploy --argument=‘(“base64.txt”)’


I have done something similar with a blob but the idea is the same with text.


  1. I create a temporary file which will be the content of the parameters for the dfx command

  2. I run dfx canister call with --argument-file $TMP_FILE

I copy my script as an example:

# Allow to upload binary to blobstore using blob type parameters
# Command sample
# dfx canister call corp_site replaceBlobRessource '(record {scheme="blob"; path="/header/test"; fragment=null; param=null},blob "\00\01\02\FF",null)' 
# dfx canister call corp_site replaceBlobRessource '(record {scheme="blob"; path="/test/b2"; fragment=null; param=null},vec{0;1;2;0xFF},null)'
# parameters:
# $1 = the uri as record
# $2 = the binary file
# Example:
# ./scripts/ 'record {scheme="png"; path="/header/logo128"; fragment=null; param=null}' '/home/willy/dev/Alternance-Theatre/corp_site/src/corp_site_assets/assets/logo128.png'



# Create beginning parameters
echo -n "( $1,blob \"" > $TMP_FILE

# Read file and create a string \xx\yy
for c in $(xxd -c 1 -p $2)
  echo -n "\\$c" >> $TMP_FILE

# Close parameters
echo -n "\",null)"  >> $TMP_FILE

echo "Parameter length: $(stat -c %s $TMP_FILE)"

# Call and store data
dfx canister call --argument-file $TMP_FILE corp_site addBlobRessource 

status=$((status + $?))


exit $((status + $?))
1 Like

A feature was added to DFX 0.11.0 that enables reading a canister argument from a file. If your file contains the full canister argument, you can use the --argument-file parameter to read directly from it. If the provided file is -, then it will be instead read from stdin, so if it doesn’t have your (""), you can arrange it with cat or similar.