Skip to content

Instantly share code, notes, and snippets.

@smddzcy
Created July 13, 2016 18:10
Show Gist options
  • Save smddzcy/6f8da82e67603f5132dcd0b57be8808f to your computer and use it in GitHub Desktop.
Save smddzcy/6f8da82e67603f5132dcd0b57be8808f to your computer and use it in GitHub Desktop.
objToFormData = (obj, formData, prefix) ->
formData ?= new FormData
formKey = null
angular.forEach obj, (val, key) ->
if prefix?
formKey = "#{prefix}[#{key}]"
else
formKey = key
if typeof val is 'object' and val.constructor isnt File
objToFormData(val, formData, formKey)
else
formData.append formKey, val
formData
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment