infobip-api-java-client icon indicating copy to clipboard operation
infobip-api-java-client copied to clipboard

How to detect file content/media type of incoming attachment

Open SzymonPek opened this issue 1 year ago • 1 comments

Hi Team, Is there a way how we can detect what is content type of file that is attached under url attribute in incoming message? Or the type of the file is always the same, VIDEO will be always mp4 format so it will be "video/mp4" and Infobip VOICE will be always "audio/ogg"? Context: When we receive incoming message with url we want to check what is the contentType so we can store in our our S3 bucket. To do it we need MIME Type of the file. To download file we use Infobip Java Client downloadWhatsAppInboundMedia().execute() but this is returning File object without extension. We tried also usage of your example with WhatsAppWebhookInboundMessageResult approach but all we get there is Infobip specific types like VOICE or IMAGE, but no details around extension.

While we acknowledge the possibility of retrieving this information via classic HTTP Requests and parsing the headers, we strive to maintain consistency in our integration and continue leveraging the Infobip API Client without introducing unnecessary complexity. Could you kindly advise if there's a method within the Infobip Java Clientthat allows us to obtain MIME Type or file extension directly from the received message?

SzymonPek avatar Mar 14 '24 17:03 SzymonPek

Hi @SzymonPek ,

We're pleased to inform you that we have an endpoint specifically designed to address this: Get WhatsApp Media Metadata.

This endpoint allows you to retrieve metadata about WhatsApp media sent by end-users, including the media type and file size, without needing to download the content itself.

Here's the endpoint documentation:

And here's an example of how to use it with the Infobip Java Client:

var api = new WhatsAppApi(API_CLIENT);

api.getWhatsAppMediaMetadata("447796344125", "123e4567-e89b-12d3-a456-426655440000");
  • The first parameter is the sender's phone number.
  • The second parameter is the media_id.

This endpoint will provide you with the necessary metadata to determine the MIME type and file extension, enabling you to store the files correctly in your S3 bucket.

Please let us know if you have any further questions or require additional assistance.

Best regards, Tamás Juhász

ib-tjuhasz avatar Mar 31 '25 13:03 ib-tjuhasz