fixes #91
This commit is contained in:
parent
c091af1622
commit
5e9709bc5b
1 changed files with 14 additions and 4 deletions
|
|
@ -33,6 +33,16 @@ proc send*(r: HttpRequest, data: Blob) {.importcpp: "#.send(#)".}
|
||||||
proc open*(r: HttpRequest; meth, url: cstring; async: bool) {.importcpp: "#.open(@)".}
|
proc open*(r: HttpRequest; meth, url: cstring; async: bool) {.importcpp: "#.open(@)".}
|
||||||
proc newRequest*(): HttpRequest {.importcpp: "new XMLHttpRequest(@)".}
|
proc newRequest*(): HttpRequest {.importcpp: "new XMLHttpRequest(@)".}
|
||||||
|
|
||||||
|
when not declared(dom.File):
|
||||||
|
type
|
||||||
|
DomFile = ref FileObj
|
||||||
|
FileObj {.importc.} = object of Blob
|
||||||
|
lastModified: int
|
||||||
|
name: cstring
|
||||||
|
else:
|
||||||
|
type
|
||||||
|
DomFile = dom.File
|
||||||
|
|
||||||
proc uploadFile*(url: cstring, file: Blob, onprogress :proc(data: ProgressEvent),
|
proc uploadFile*(url: cstring, file: Blob, onprogress :proc(data: ProgressEvent),
|
||||||
cont: proc (httpStatus: int; response: cstring);
|
cont: proc (httpStatus: int; response: cstring);
|
||||||
headers: openarray[(cstring, cstring)] = []) =
|
headers: openarray[(cstring, cstring)] = []) =
|
||||||
|
|
@ -44,7 +54,7 @@ proc uploadFile*(url: cstring, file: Blob, onprogress :proc(data: ProgressEvent)
|
||||||
|
|
||||||
var formData = newFormData()
|
var formData = newFormData()
|
||||||
formData.append("upload_file",file)
|
formData.append("upload_file",file)
|
||||||
formData.append("filename", dom.File(file).name)
|
formData.append("filename", DomFile(file).name)
|
||||||
let ajax = newRequest()
|
let ajax = newRequest()
|
||||||
ajax.open("POST", url, true)
|
ajax.open("POST", url, true)
|
||||||
for a, b in items(headers):
|
for a, b in items(headers):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue