-
Notifications
You must be signed in to change notification settings - Fork 656
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
WebClient.files.upload is broken #196
Comments
By convention in the API we use
The full arguments the
NOTE: the above was written with the 3.0.0 version of the client, it's the same basic principle for 2.3.0, but I haven't looked at the old JSDoc there. |
I'll add an example to the README of how to do a file upload in a sec and close this issue once I have. |
You guys broke this API, upgraded from 2.3.0 and my files uploading just stopped working. |
First Attempt (and Failure)
To start out, I figured I'd try using
form-data
to create the multipart form.So I ran that and got the following error:
The documentation says that
invalid_array_arg
meansThe method was passed a PHP-style array argument (e.g. with a name like foo[7]). These are never valid with the Slack API.
, but we're not explicitly passing in any sort of PHP-style array (or even an array at all).I decided to look under the hood to see what was happening and found that the
FormData
stream object isn't being read as a stream at all. Instead, it's being serialized by the API client into a PHP-style form array, causing the error. Here's a screenshot of what the beginning of my RequestB.in looked like when testing this:Second Attempt (and Failure)
Alright, so I decided to try manually serializing a file as a
multipart/form-data
string and then pass that in.Having
[object Object]
as the file's body is invalid for PNG files, but it shouldn't prevent it from being uploaded. Uploading a PNG file with those contents manually works fine in Slack.This time I got a different error:
Third Attempt (and Failure)
As a last ditch effort, I tried passing in the contents of a file directly as a string (with no
multipart/form-data
wrapping).And got the same error:
Attempt at Figuring Out the Problem
I checked out the request made by the API tester on https://api.slack.com/methods/files.upload/test and it looks like all of the arguments besides the file are passed through the URL (like
https://slack.com/api/files.upload?token=xxx&channels=xxx
), while the file is submitted as a multipart form as the POST body.There are currently two issues with the way the API client handles
files.upload
:Content-Type
sent isapplication/x-www-form-urlencoded
(and the contents of the request match that).files.upload
, making it very difficult to upload any sort of real file.The text was updated successfully, but these errors were encountered: