fix
add content-Type to contract
| | |
| | | "bytes" |
| | | "fmt" |
| | | "github.com/gin-gonic/gin" |
| | | "github.com/h2non/filetype" |
| | | "go.uber.org/zap" |
| | | "net/http" |
| | | "srm/global" |
| | |
| | | // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" |
| | | // @Router /con/createContract [post] |
| | | func (conApi *ContractApi) CreateContract(c *gin.Context) { |
| | | name := c.Param("name") |
| | | name := c.PostForm("name") |
| | | file, err := c.FormFile("file") |
| | | if err != nil { |
| | | c.JSON(400, gin.H{"error": err.Error()}) |
| | |
| | | defer f.Close() |
| | | f.Read(fileContent) |
| | | |
| | | // 重置文件指针 |
| | | f.Seek(0, 0) |
| | | |
| | | // 使用 filetype 库检测文件类型 |
| | | kind, _ := filetype.Match(fileContent) |
| | | if kind == filetype.Unknown { |
| | | c.JSON(http.StatusBadRequest, gin.H{"error": "Unknown file type"}) |
| | | return |
| | | } |
| | | |
| | | contract := test.Contract{ |
| | | FileName: name, |
| | | FileContent: fileContent, |
| | | FileType: kind.MIME.Value, |
| | | } |
| | | |
| | | if err, id := conService.CreateContract(&contract); err != nil { |
| | |
| | | response.FailWithMessage("创建失败", c) |
| | | } else { |
| | | //response.OkWithMessage("创建成功", c) |
| | | response.OkWithData(gin.H{"id": id}, c) |
| | | response.OkWithData(gin.H{"id": id, "name": name}, c) |
| | | } |
| | | } |
| | | |
| | |
| | | c.Header("Content-Description", "File Transfer") |
| | | c.Header("Content-Transfer-Encoding", "binary") |
| | | c.Header("Content-Disposition", fmt.Sprintf("attachment; filename=%s", contract.FileName)) |
| | | c.Header("Content-Type", "application/pdf") |
| | | c.Header("Content-Type", contract.FileType) |
| | | |
| | | // 将文件作为响应体发送 |
| | | http.ServeContent(c.Writer, c.Request, contract.FileName, time.Now(), reader) |
| | |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "fileType", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "description": "主键ID", |
| | | "name": "id", |
| | |
| | | { |
| | | "type": "string", |
| | | "name": "fileName", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "fileType", |
| | | "in": "query" |
| | | }, |
| | | { |
| | |
| | | { |
| | | "type": "string", |
| | | "name": "fileName", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "fileType", |
| | | "in": "query" |
| | | }, |
| | | { |
| | |
| | | { |
| | | "type": "string", |
| | | "name": "fileName", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "fileType", |
| | | "in": "query" |
| | | }, |
| | | { |
| | |
| | | "fileName": { |
| | | "type": "string" |
| | | }, |
| | | "fileType": { |
| | | "type": "string" |
| | | }, |
| | | "id": { |
| | | "description": "主键ID", |
| | | "type": "integer" |
| | |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "fileType", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "description": "主键ID", |
| | | "name": "id", |
| | |
| | | { |
| | | "type": "string", |
| | | "name": "fileName", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "fileType", |
| | | "in": "query" |
| | | }, |
| | | { |
| | |
| | | { |
| | | "type": "string", |
| | | "name": "fileName", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "fileType", |
| | | "in": "query" |
| | | }, |
| | | { |
| | |
| | | { |
| | | "type": "string", |
| | | "name": "fileName", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "fileType", |
| | | "in": "query" |
| | | }, |
| | | { |
| | |
| | | "fileName": { |
| | | "type": "string" |
| | | }, |
| | | "fileType": { |
| | | "type": "string" |
| | | }, |
| | | "id": { |
| | | "description": "主键ID", |
| | | "type": "integer" |
| | |
| | | type: array |
| | | fileName: |
| | | type: string |
| | | fileType: |
| | | type: string |
| | | id: |
| | | description: 主键ID |
| | | type: integer |
| | |
| | | - in: query |
| | | name: fileName |
| | | type: string |
| | | - in: query |
| | | name: fileType |
| | | type: string |
| | | - description: 主键ID |
| | | in: query |
| | | name: id |
| | |
| | | type: array |
| | | - in: query |
| | | name: fileName |
| | | type: string |
| | | - in: query |
| | | name: fileType |
| | | type: string |
| | | - description: 主键ID |
| | | in: query |
| | |
| | | type: array |
| | | - in: query |
| | | name: fileName |
| | | type: string |
| | | - in: query |
| | | name: fileType |
| | | type: string |
| | | - description: 主键ID |
| | | in: query |
| | |
| | | - in: query |
| | | name: fileName |
| | | type: string |
| | | - in: query |
| | | name: fileType |
| | | type: string |
| | | - description: 主键ID |
| | | in: query |
| | | name: id |
| | |
| | | github.com/gofrs/uuid/v5 v5.0.0 |
| | | github.com/golang-jwt/jwt/v4 v4.5.0 |
| | | github.com/gookit/color v1.5.4 |
| | | github.com/h2non/filetype v1.1.3 |
| | | github.com/huaweicloud/huaweicloud-sdk-go-obs v3.21.8+incompatible |
| | | github.com/jordan-wright/email v0.0.0-20200824153738-3f5bafa1cd84 |
| | | github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible |
| | |
| | | github.com/robfig/cron/v3 v3.0.1 |
| | | github.com/sashabaranov/go-openai v1.14.1 |
| | | github.com/shirou/gopsutil/v3 v3.23.6 |
| | | github.com/shopspring/decimal v1.3.1 |
| | | github.com/songzhibin97/gkit v1.2.11 |
| | | github.com/spf13/cast v1.5.1 |
| | | github.com/spf13/viper v1.16.0 |
| | |
| | | github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect |
| | | github.com/rogpeppe/go-internal v1.11.0 // indirect |
| | | github.com/shoenig/go-m1cpu v0.1.6 // indirect |
| | | github.com/shopspring/decimal v1.3.1 // indirect |
| | | github.com/spf13/afero v1.9.5 // indirect |
| | | github.com/spf13/jwalterweatherman v1.1.0 // indirect |
| | | github.com/spf13/pflag v1.0.5 // indirect |
| | |
| | | github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc= |
| | | github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE= |
| | | github.com/PuerkitoBio/purell v1.1.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= |
| | | github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= |
| | | github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= |
| | | github.com/QcloudApi/qcloud_sign_golang v0.0.0-20141224014652-e4130a326409/go.mod h1:1pk82RBxDY/JZnPQrtqHlUFfCctgdorsd9M06fMynOM= |
| | | github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM= |
| | |
| | | github.com/aws/aws-sdk-go v1.44.307 h1:2R0/EPgpZcFSUwZhYImq/srjaOrOfLv5MNRzrFyAM38= |
| | | github.com/aws/aws-sdk-go v1.44.307/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI= |
| | | github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= |
| | | github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= |
| | | github.com/bsm/ginkgo/v2 v2.7.0 h1:ItPMPH90RbmZJt5GtkcNvIRuGEdwlBItdNVoyzaNQao= |
| | | github.com/bsm/gomega v1.26.0 h1:LhQm+AFcgV2M0WyKroMASzAzCAJVpAxQXv4SaI9a69Y= |
| | | github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= |
| | |
| | | github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= |
| | | github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI= |
| | | github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= |
| | | github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= |
| | | github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee h1:s+21KNqlpePfkah2I+gwHF8xmJWRjooY+5248k6m4A0= |
| | | github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee/go.mod h1:L0fX3K22YWvt/FAX9NnzrNzcI4wNYi9Yku4O0LKYflo= |
| | | github.com/gobwas/pool v0.2.0 h1:QEmUOlnSjWtnpRGHF3SauEiOsy82Cup83Vf2LcMlnc8= |
| | |
| | | github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= |
| | | github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM= |
| | | github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= |
| | | github.com/h2non/filetype v1.1.3 h1:FKkx9QbD7HR/zjK1Ia5XiBsq9zdLi5Kf3zGyFTAFkGg= |
| | | github.com/h2non/filetype v1.1.3/go.mod h1:319b3zT68BvV+WRj7cwy856M2ehB3HqNOt6sy1HndBY= |
| | | github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= |
| | | github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= |
| | | github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= |
| | |
| | | github.com/huaweicloud/huaweicloud-sdk-go-obs v3.21.8+incompatible/go.mod h1:l7VUhRbTKCzdOacdT4oWCwATKyvZqUOlOqr0Ous3k4s= |
| | | github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= |
| | | github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= |
| | | github.com/jackc/chunkreader/v2 v2.0.1/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk= |
| | | github.com/jackc/pgconn v1.13.0/go.mod h1:AnowpAqO4CMIIJNZl2VJp+KrkAZciAkhEl0W0JIobpI= |
| | | github.com/jackc/pgio v1.0.0/go.mod h1:oP+2QK2wFfUWgr+gxjoBH9KGBb31Eio69xUb0w5bYf8= |
| | | github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= |
| | | github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= |
| | | github.com/jackc/pgproto3/v2 v2.3.1/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA= |
| | | github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk= |
| | | github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= |
| | | github.com/jackc/pgtype v1.12.0/go.mod h1:LUMuVrfsFfdKGLw+AFFVv6KtHOFMwRgDDzBt76IqCA4= |
| | | github.com/jackc/pgx/v4 v4.17.2/go.mod h1:lcxIZN44yMIrWI78a5CpucdD14hX0SBDbNRvjDBItsw= |
| | | github.com/jackc/pgx/v5 v5.3.1 h1:Fcr8QJ1ZeLi5zsPZqQeUZhNhxfkkKBOgJuYkJHoBOtU= |
| | | github.com/jackc/pgx/v5 v5.3.1/go.mod h1:t3JDKnCBlYIc0ewLF0Q7B8MXmoIaBOZj/ic7iHozM/8= |
| | | github.com/jcmturner/aescts/v2 v2.0.0/go.mod h1:AiaICIRyfYg35RUkr8yESTqvSy7csK90qZ5xfvvsoNs= |
| | |
| | | github.com/lestrrat-go/strftime v1.0.6 h1:CFGsDEt1pOpFNU+TJB0nhz9jl+K0hZSLE205AhTIGQQ= |
| | | github.com/lestrrat-go/strftime v1.0.6/go.mod h1:f7jQKgV5nnJpYgdEasS+/y7EsTb8ykN2z68n3TtcTaw= |
| | | github.com/lib/pq v1.10.2 h1:AqzbZs4ZoCBp+GtejcpCpcxM3zlSMx29dXbUSeVtJb8= |
| | | github.com/lib/pq v1.10.2/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= |
| | | github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4= |
| | | github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I= |
| | | github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= |
| | |
| | | go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= |
| | | go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= |
| | | go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI= |
| | | go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= |
| | | go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU= |
| | | go.uber.org/multierr v1.8.0 h1:dg6GjLku4EH+249NNmoIciG9N/jURbDG+pFlTkhzIC8= |
| | | go.uber.org/multierr v1.8.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak= |