dongqigu0429 2018-08-10 14:25
浏览 4

发布文件位置

I am trying to send this request through a POST using Go.

curl https://api.onfido.com/v2/applicants/1030303-123123-123123/documents \
  -H 'Authorization: Token token=your_api_token' \
  -F 'type=passport' \
  -F 'file=@localfile.png;type=image/png'

At this moment I can't figure out how to deal with the -F parameter.

I've created the following struct

type DocumentRequest struct {
    Type string `json:"type"`
    File string `json:"file"`
}

which I am sending through:

res, err := s.Post(assembleURL(“https://api.onfido.com/v2/applicants/", userID, "documents"), d, doc, &apiErr)

where d is my DocumentRequest.

Any tips on how to solve it?

Thanks!

  • 写回答

1条回答 默认 最新

  • dsjgk330337 2018-08-10 15:59
    关注

    You're gonna have to read the file and add it as the request body. There's a helper in ioutils and you can just get rid of your struct and pass the body directly. This is the gist of it. Ofc, you should handle the err's and you might need to prepare your req up front so you can add additional headers before sending.

    body, err := ioutils.ReadFile(yourPath)
    reqs, err := http.Post(uri, "image/png", &body)
    
    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程