title: How can I publish a file using Mosquitto in python?
body: <p>I am using python-mosquitto to subscribe to my MQTT broker which support file type uploads. I can use it just fine using the -f flag when going from Mosquitto on the command line. However, I can't figure out how to use the client.publish(topic, payload) to specify a file to publish when doing it from within my python script. </p>
  
  <p>Python mosquitto gives me the error <code>TypeError: payload must be a string, bytearray, int, float or None.</code> when I try to throw something weird at it. I have a file stored in local directory already which I want to specify as the payload of the publish. </p>
  
  <p>I'm experienced with MQTT but my python is very rusty, I am assuming I need to do some type of file stream function here, but not sure how to do it.</p>
  
  <p>I want to specify the image here: <code>mqttc.publish("/v3/device/file", NEED_TO_SPECIFY_HERE)</code></p>
  
  <p>I have tried opening the image by doing:</p>
  
  <pre><code>    f = open("/home/pi/mosq/imagecap/imagefile.jpg", "rb")
      imagebin = f.read()
      mqttc.publish("/v3/device/file", imagebin)
  </code></pre>
  
  <p>But that didn't work and neither did <code>mqttc.publish("/v3/device/file", bytearray(open('/tmp/test.png', 'r').read()))</code></p>
  
  <p>The client.publish doesnt throw an error with those, but the file is not received properly by the broker. Any ideas?</p>
  
  <p>Thanks!!</p>