0
我想要一些關於我的代碼的幫助。我的目標是在httpResponse中同時發送字符串變量作爲ini純文本和bmp文件。django的多部分httpresponse
目前,我將bmp文件的解碼字節插入ini參數中,考慮到我使用只有客戶端但不是服務器的對講機進行通信,所以我只能生成httpresponses但沒有請求。
如果我base64編碼我的圖像,我需要改變我們的對講機的軟件來解碼它,目前我不能,你能告訴我,base64編碼字節在我的情況下是強制性的嗎?
我在網上做了一些研究,我看到人們base64編碼他們的圖像或他們做出多部分響應。
您能否幫我實施一個多部分響應,甚至是手工製作,這會讓我感興趣?
我告訴你我是如何的時刻做,我把圖像中的「串」 INI參數:
def send_bmp():
outputConfig = io.StringIO()
outputConfig.write('[RETURN_INFO]\r\n')
outputConfig.write('config_id=255\r\n')
outputConfig.write('config_type=2\r\n')
outputConfig.write('action=3\r\n')
outputConfig.write('[DATABASE]\r\n')
file = open(django_settings.TMP_DIR+'/qrcode.bmp', 'rb').read()
outputConfig.write('size_all='+str(len(file))+'\r\n')
outputConfig.write('string='+file.decode('iso-8859-1')+'\r\n')
outputConfig.write('csum='+str(sum(file))+'\r\n')
body = outputConfig.getvalue()
httpR = HttpResponse(body, content_type='text/plain;charset=iso-8859-1')
httpR['Content-Length'] = len(body)
return httpR
這裏是響應我得到:
https://gist.github.com/Ezekiah/e6fd50f13c05f338f27a