donglin7979 2014-09-26 15:38
浏览 25
已采纳

如何创建包含多个FileHeader的http请求?

I am trying to test a uploading service that supports multiple files uploading,and I found this:

golang POST data using the Content-Type multipart/form-data

that introduced how to create a request to upload a single file,but I need to upload multiple files,is there simple way to create this kind of request?

update:

please check line:38 and 39 in post:to support html5 multiple files uploading


line 38    files := m.File["myfiles"]
line 29      for i, _ := range files {

It seems that it needs to set single name for multiple file headers to stimulate the html5 multiple files uploading.

  • 写回答

1条回答 默认 最新

  • dongshandun4363 2014-09-26 16:08
    关注

    For each file, call CreateFormFile to create the header for the file. Call Write on the writer returned from CreateFormFile one or more times to write data to the file. When done with all files, close the multipart writer.

    The top answer in the linked question uploads two files, one named "image" and one named "key". The data for the "image" is copied from a file. The data for "key" is simply the bytes "KEY".

    The field name is the first argument to CreateFormFile. If you want to upload multiple files with the same name, use the same name each time you call CreateFormFile.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)