This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

HTTP PUT image to 2N intercom
#2
Try this. filedata variable must contain your image in JPEG format. Use io.readfile() to read a local file.
Code:
require('ltn12')
require('ssl.https')

boundary = os.date('%d%m%Y%H%M%S')
filedata = '...' -- image data as a binary string

body = table.concat({
  '--' .. boundary,
  'Content-Disposition: form-data; name="blob-image"; filename="picture.jpeg"',
  'Content-Type: image/jpeg',
  '',
  filedata,
  '--' .. boundary .. '--',
  ''
}, '\r\n')

resp = {}

res, code, response_headers, status = ssl.https.request({
  url = 'https://test:test@10.0.0.230/api/display/image?display=ext1',
  sink = ltn12.sink.table(resp),
  method = 'PUT',
  source = ltn12.source.string(body),
  headers = {
    ['content-length'] = #body,
    ['content-type'] = 'multipart/form-data; boundary=' .. boundary
  }
})

log(res, code, table.concat(resp))

For digest auth you can use this example: https://forum.logicmachine.net/showthrea...64#pid9364
Replace ssl.https.request in the above code with request from the digest code.
Reply


Messages In This Thread
HTTP PUT image to 2N intercom - by coolaew - 07.02.2023, 23:57
RE: HTTP PUT image to 2N intercom - by admin - 08.02.2023, 11:21
RE: HTTP PUT image to 2N intercom - by admin - 09.02.2023, 07:58

Forum Jump: