亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

當源是 multipart.File 時,image.Decode 導致“未知格式”

當源是 multipart.File 時,image.Decode 導致“未知格式”

Go
喵喔喔 2021-10-18 10:27:35
我有一個multipart.File用戶上傳到我的服務器,然后我使用該文件并將其上傳到 s3 aws-sdk-go,但我也想創建該圖像的縮略圖。當我file是os.Open(...本地文件的返回值時,下面的代碼在我的測試中工作正常,但是err當我發送CreateThumbnail與我發送到的相同變量時,它擊中了塊s3,它要求一個io.Readerimport (  "image"  "image/jpeg")func UploadToS3(file multipart.File, /*snip*/) {  _, uploadErr := uploader.Upload(&s3manager.UploadInput{    Bucket: aws.String(bucket),    Key:    aws.String(key),    Body:   file,    ContentType: aws.String(mimeType),    ACL: aws.String("public-read"),  })  reader, err := CreateThumbnail(file)}    func CreateThumbnail(imageFile io.Reader) (io.Reader, error) {  decodedImage, _, err := image.Decode(imageFile)  if err != nil {   fmt.Println("Error decoding", err, decodedImage) // "unknown format"   return nil, err } /*snip*/我看到的大多數問題的答案都涉及添加import _ "image/jpeg",但已經導入(以及png和gif)。我對 Golang 還很陌生,所以我對自己做錯了什么有點迷茫。我也嘗試image.Decode(bufio.NewReader(imageFile))過,但結果相同err。
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 242 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號