harmonyzhang / whatsapp-business-java-sdk

Whatsapp business api SDK, written in java. This SDK implements the Official Whatsapp Cloud API and WhatsApp Business Management API and Engagelab Whatsapp API.
https://harmonyzhang.github.io/whatsapp-business-java-sdk/
MIT License
14 stars 5 forks source link

Upload media not work #5

Closed pcomp96 closed 1 year ago

pcomp96 commented 1 year ago

Hi @harmonyzhang, First of all, thank you for this repository, is very useful.


I implemented everything easily and now I'm doing the testing phase, a week ago I launched the tests for the uploadMedia and it worked. Today launching a test with the average upload, it failed. The exception thrown comes from the library

java.lang.NoSuchMethodError: okhttp3.MultipartBody.create([BLokhttp3/MediaType;)Lokhttp3/RequestBody; at com.whatsapp.api.impl.WhatsappBusinessCloudApi.uploadMedia([WhatsappBusinessCloudApi.java:73]

Go to WhatsappBusinessCloudApi.uploadMedia

  public UploadResponse uploadMedia(String phoneNumberId, String fileName, FileType fileType, byte[] file) {

        RequestBody requestFile = MultipartBody.create(file, MediaType.parse(fileType.getType()));

           .......
    }

From the source code I see that there is no method with this signature: MultipartBody.create(byte[] file, MediaType fileType);


There is a method that has this signature and I think you need to change this line so as not to throw this exception.

code

For the solution I think it would be enough just to reverse the parameters passed to the method.

I hope you find this observation useful, I remain available for clarification .. Thank you! 😉

harmonyzhang commented 1 year ago

Thanks for your feedback, the issue has been fixed in v1.0.1