Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UploadFileV2 uploads incorrectly when using text Content parameter #1290

Closed
calebmckay opened this issue May 24, 2024 · 0 comments · Fixed by #1291
Closed

UploadFileV2 uploads incorrectly when using text Content parameter #1290

calebmckay opened this issue May 24, 2024 · 0 comments · Fixed by #1291

Comments

@calebmckay
Copy link
Contributor

What happened

When calling UploadFileV2() with a string passed to the Content parameter, the file is incorrectly uploaded. This seems to be because old files.upload endpoint allowed text content to be passed as a POST parameter, but the new upload URL interprets the unexpected content= parameter as the start of the file content, and doesn't correctly URL-decode it.

Screenshot 2024-05-23 at 8 23 05 PM

Expected behavior

Screenshot 2024-05-23 at 8 25 09 PM

Steps to reproduce

reproducible code

package main

import (
	"os"

	"github.com/slack-go/slack"
)

func main() {
	token := os.Getenv("SLACK_AUTH_TOKEN")
	channelId := os.Getenv("SLACK_CHANNEL_ID")
	client := slack.New(token, slack.OptionDebug(true))

	fileContent := "This is test file content"
	fileSize := len(fileContent)

	fileParams := slack.UploadFileV2Parameters{
		Channel:        channelId,
		Content:        fileContent,
		Filename:       "file.txt",
		FileSize:       fileSize,
		InitialComment: "Test file",
		Title:          "Test file",
	}
	client.UploadFileV2(fileParams)
}

This seems to only be an issue with the Content parameter, as converting the string to a Reader fixes the problem:

reader := strings.NewReader(fileContent)

fileParams := slack.UploadFileV2Parameters{
	Channel:        channelId,
	Reader:         reader,
	Filename:       "file.txt",
	FileSize:       fileSize,
	InitialComment: "Test file",
	Title:          "Test file",
}
client.UploadFileV2(fileParams)

Versions

  • Go: go version go1.20.7 darwin/arm64
  • slack-go/slack: v0.13.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant