Skip to content

Instantly share code, notes, and snippets.

@timoxley
Created November 10, 2011 03:28
Show Gist options
  • Save timoxley/1354024 to your computer and use it in GitHub Desktop.
Save timoxley/1354024 to your computer and use it in GitHub Desktop.
multipartform encoding image woes
var fileBody = fs.readFileSync(image1, 'binary')
var fileName = path.basename(image1)
var mimeType = mime.lookup(image1)
console.log(mimeType)
var headers = {
'Accept': 'application/json',
'Content-Type': 'multipart/form-data; boundary=----WebKitFormBoundaryMfJEpQcCbybb6A8U'
}
var body = [
'------WebKitFormBoundaryMfJEpQcCbybb6A8U',
'Content-Disposition: form-data; name="caption"',
'',
'a caption',
'------WebKitFormBoundaryMfJEpQcCbybb6A8U',
'Content-Disposition: file; name="attachment"; filename="'+fileName+'"',
'Content-Type: ' + mimeType,
'Content-Transfer-Encoding: binary',
'Content-Length' + Buffer.byteLength(fileBody),
'',
fileBody,
'------WebKitFormBoundaryMfJEpQcCbybb6A8U--\r\n'
].join('\r\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment