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

Unsupported Buffer file type on sending buffer containing js file #350

Closed
Hypfer opened this issue Jun 9, 2017 · 6 comments
Closed

Unsupported Buffer file type on sending buffer containing js file #350

Hypfer opened this issue Jun 9, 2017 · 6 comments

Comments

@Hypfer
Copy link

Hypfer commented Jun 9, 2017

I'm using the current master git branch.

Expected Behavior

Send buffer containing the contents of a .js file

Actual Behavior

Unhandled rejection Error: EFATAL: Unsupported Buffer file type

telegram.js:249 seems to be the problem.

const filetype = fileType(data);
      if (!filetype) {
        throw new errors.FatalError('Unsupported Buffer file type');
      }

Steps to reproduce the Behavior

Send buffer containing plain text

@Hypfer
Copy link
Author

Hypfer commented Jun 9, 2017

Why exactly are you checking if the document is a "valid file type" anyways?

Since telegram allows any "file" to be sent via document this doesn't seem reasonable to me.

@yagop
Copy link
Owner

yagop commented Jun 9, 2017

It's because contentType has to be provided to Telegram.

It's weird file type isn't detected. Maybe should provide a default content-type (application/octet-stream or text/plain)

@0xallie
Copy link

0xallie commented Jun 17, 2017

I have the same issue with MP3 not being detected. Could you add an option to explicitly specify the MIME type?

@GochoMugo
Copy link
Collaborator

background

It is easier to have the library auto-detect the MIME type, thus abstracting all that from the user. But advanced users may want to handle that on their own.

When using type auto-detection, we should throw an error if it fails. This avoids situations where bots send files to their users using a probably wrong type.

suggested fix
  1. Allow specifying the MIME type when invoking methods
  2. If none is specified, detect the type (as we are currently doing)

@GochoMugo GochoMugo added the TODO label Jun 22, 2017
GochoMugo added a commit that referenced this issue Jun 28, 2017
@GochoMugo
Copy link
Collaborator

Update:
  1. created feature branch: feature/explicit-mime-type
    1. check out commit bdc79a4: allows specifying the MIME type explicitly

@GochoMugo
Copy link
Collaborator

In v0.30.0, the file type of a buffer, if not be detectable, defaults to "application/octet-stream".

NOTE: For now, this has to be manually activated using environment variable NTBA_FIX_350. (It is an API-breaking change!).

See the updated docs on sending files, particularly here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants