Created
January 2, 2019 19:44
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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