`error_creating_file_sync` when using `files.upload`
Description
Uploading a post file in response to a slash command fails on random occasions.
What type of issue is this? (place an x in one of the [ ])
- [x] bug
- [ ] enhancement (feature request)
- [ ] question
- [ ] documentation related
- [ ] example code related
- [ ] testing related
- [ ] discussion
Requirements (place an x in each of the [ ])
- [x] I've read and understood the Contributing guidelines and have done my best effort to follow them.
- [x] I've read and agree to the Code of Conduct.
- [x] I've searched for any related issues and avoided creating a duplicate issue.
Bug Report
Filling out the following details about bugs will help us solve your issue sooner.
Reproducible in:
package version: 3.12.1
node version: 16.15.0
OS version(s): Ubuntu 20.04.4 LTS (GNU/Linux 5.13.0-1025-aws x86_64)
Steps to reproduce:
- The file is read with fs.readFileSync.
- A user token is used. (This issue has happened to multiple users. The users have granted the app
files.writepermission) The file type ispost. - Upload the file with the files.upload endpoint
- The uploading happens in response to a user using a slash command. There are some API calls to external parties that could take some time before the file is uploaded.
Sample post file file.post:
[] item 1
[] item 2
_Some notes_
Sample script to upload the file:
import {App} from '@slack/bolt';
import {WebClient} from '@slack/web-api';
import fs from 'fs';
const FILE = fs.readFileSync('/some/path/to/file.post');
const upload = async (client: WebClient, channelId: string, token: string) => {
await client.files.upload({
channels: channelId,
file: FILE,
filename: 'Some post name',
filetype: 'post',
token,
});
};
const getUserToken = (userId: string) => {
// get user token by user ID
};
const useSlashCommand = (app: App) => {
app.command('/command', async({ack, client, command}) => {
await ack();
const token = getUserToken(command.user_id);
await upload(client, command.channel_id, token);
});
};
Expected result:
The file to be always uploaded successfully.
Actual result:
Sometimes (maybe 10% of the time?) the upload function will throw an error like this
{
"code": "slack_webapi_platform_error",
"data": {
"ok": false,
"error": "error_creating_file_sync",
"response_metadata": {
"scopes": ["identify", "chat:write", "files:write"],
"acceptedScopes": ["files:write"]
}
}
}
which is not helpful at all. Also the error code error_creating_file_sync is not listed on the docs describing the endpoint.
This happens seemingly randomly so it's very difficult to debug.
Attachments:
The file is not big, by the way. It is just around 2KB. So I don't think it is related to this issue: https://github.com/slackapi/python-slack-sdk/issues/1191
It is also a static file.
Hey @secure12, this is unfortunately a known issue with our backend. Apologies for this. Intermittently, file uploads will fail due to security scanning on the backend. This is the same as https://github.com/slackapi/python-slack-sdk/issues/1191, as you identified, but also https://github.com/slackapi/python-slack-sdk/issues/1165.
Do you by any chance have an exact timestamp of when the last failure you saw happened?
Thanks for your prompt response. It happened once at Sep 13 09:45:23 UTC. It is unintuitive that this is related to security scanning though because sometimes it goes through
We are going to add a new way to upload files soon. See also: https://github.com/slackapi/node-slack-sdk/issues/1541#issuecomment-1265164652
With files.uploadV2 being public should we close this issue? @seratch
Yeah, let's do so!