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

Determining extension of message content #23

Closed
samwierema opened this issue Oct 12, 2016 · 8 comments
Closed

Determining extension of message content #23

samwierema opened this issue Oct 12, 2016 · 8 comments

Comments

@samwierema
Copy link

samwierema commented Oct 12, 2016

When retrieving the content of a message (e.g. an image) it can not be determined, using the SDK, whether the image (or any other content) is of a given mime type (e.g. image/jpeg, image/png). This makes it hard to actually write the file to disk with the right extension.

Here's some example code that shows the issue:

// $message is an instance of ImageMessage

$line = new LINEBot(new CurlHTTPClient('<token>'), [
    'channelSecret' => '<secret>'
]);

$response = $line->getMessageContent($message->getMessageId());
if ($response->isSucceeded()) {
    // I can get the binary body with $response->getRawBody()
    // but I can't get the mime type, nor the extension.
    $filePath = tmpfile() . '<extension?>';
    file_put_contents($filePath, $response->getRawBody());
}

There's various solutions to the issue:

  • I can create my own HTTPClient with a getMimeType() method, but since it's a private member of the LINEBot class, I can't access this in the code.
  • In addition to the above I can overwrite the Response class, but that just seems to much overwriting already.
  • Do the above, but in this repository
  • Get the extension and/or from the ImageMessage class (if sent back from the API)

In the KitchenSink example all images are written as .jpeg so it could be that all images are actually JPEG's, but that is not documented.

Could someone provide some guidance to the above? I can make a pull request based on suggestion and/or feedback, but looking to see what the right way to go is.

@samwierema
Copy link
Author

I've created an example fix in pull request #24. If you think that is the way to go, please do merge.

@moznion
Copy link
Contributor

moznion commented Oct 12, 2016

Thank you for your suggestion and a patch. Looks cool!

However, I think it doesn't have to limit to Content-Type header. I feel it is better to be able to provide all of the header contents. That way, users of the SDK would be able to get any of the headers.

How do you think?

@moznion
Copy link
Contributor

moznion commented Oct 14, 2016

@samwierema ping

@samwierema
Copy link
Author

Yes, I think that might be helpful, although I can't necessarily tell why all headers are needed. Would you then also have methods for each header, or would you access them in a different way?

@moznion
Copy link
Contributor

moznion commented Oct 14, 2016

Thank you.
I'll write PoC code to solve this problem, then could you review that?

@samwierema
Copy link
Author

Yes, perfect. If you need any further input or feedback, let me know.

@moznion
Copy link
Contributor

moznion commented Oct 14, 2016

I copy.

@moznion
Copy link
Contributor

moznion commented Oct 19, 2016

Version 1.1.0 supports such functions!
https://github.com/line/line-bot-sdk-php/releases/tag/1.1.0

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

2 participants