Skip to content

Instantly share code, notes, and snippets.

@nubunto
Created January 2, 2019 19:44
Show Gist options
  • Save nubunto/030bead224f1829c60149b0b04d2c19e to your computer and use it in GitHub Desktop.
Save nubunto/030bead224f1829c60149b0b04d2c19e to your computer and use it in GitHub Desktop.
Slack: "no_file_data" error when forgetting to supply the Filename field when using a Reader
package main
import (
"fmt"
"os"
"github.com/nlopes/slack"
)
func main() {
api := slack.New(os.Getenv("SLACK_TOKEN"))
fileParams := slack.FileUploadParameters{
File: "my-image.png",
Channels: []string{"somechannel"},
}
if _, err := api.UploadFile(fileParams); err != nil {
fmt.Printf("[fileParams] slack error: %v", err)
// works as expected
return
}
myImage, err := os.Open("my-image.png")
if err != nil {
fmt.Printf("error opening file: %v", err)
os.Exit(1)
}
readerParams := slack.FileUploadParameters{
Reader: myImage,
Channels: []string{"somechannel"},
}
if _, err := api.UploadFile(readerParams); err != nil {
fmt.Printf("[readerParams] slack error: %v", err)
// fails with "no_file_data"
return
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment