curl 命令行 文件上传

本案例使用golang版本

  • golang后端实现代码上传
package main 

import (
    "github.com/gin-gonic/gin"
    "log"
)

func main() {
        r := gin.Default()
        //file upload
        r.POST("/upload", func(c *gin.Context) {
            //单文件
            file, _ := c.FormFile("file")
            log.Println(file.Filename)

            //上传文件到指定目录
            //c.SaveUploadedFile(file, dst)
            c.String(http.StatusOK, fmt.Sprintf("'%s' uploaded!", file.Filename))
        })
        r.Run()
}
  • curl 命令行模拟 单文件上传
curl -X POST -H "Content-Type: multipart/form-data" -F "file=@C:/Users/admin/Desktop/637b
edd29930a9da2a4131190d890b7a.jpg" http://localhost:8080/upload
  • 返回结果

'637bedd29930a9da2a4131190d890b7a.jpg' uploaded!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容