diff --git a/image.jpg b/image.jpg deleted file mode 100644 index 297a3f9..0000000 Binary files a/image.jpg and /dev/null differ diff --git a/prova.png b/prova.png deleted file mode 100644 index fd0bd85..0000000 Binary files a/prova.png and /dev/null differ diff --git a/src/com/em/miguelbridge/botmatrix/MatrixBot.java b/src/com/em/miguelbridge/botmatrix/MatrixBot.java index bd10008..93a8aa9 100644 --- a/src/com/em/miguelbridge/botmatrix/MatrixBot.java +++ b/src/com/em/miguelbridge/botmatrix/MatrixBot.java @@ -2,6 +2,7 @@ package com.em.miguelbridge.botmatrix; import com.em.miguelbridge.Launcher; +import java.awt.image.BufferedImage; import java.io.*; import java.net.URISyntaxException; import java.net.URLEncoder; @@ -9,6 +10,8 @@ import java.net.URLEncoder; import org.json.simple.*; import org.json.simple.parser.*; +import javax.imageio.ImageIO; + /** * @author Emanuele Magon */ @@ -139,13 +142,27 @@ public class MatrixBot { JSONObject reqParams = new JSONObject(); JSONObject objInfo = new JSONObject(); + JSONObject thumb = new JSONObject(); + BufferedImage bimg = ImageIO.read(file); + int width = bimg.getWidth(); + int height = bimg.getHeight(); - objInfo.put("mimetype", "image/jpg"); + thumb.put("mimetype", "image/jpeg"); + thumb.put("h", height); + thumb.put("w", width); + thumb.put("size", file.length()); + + objInfo.put("mimetype", "image/jpeg"); objInfo.put("size", file.length()); + //objInfo.put("thumbnail_info", thumb); + //objInfo.put("thumbnail_url", uriFile); + objInfo.put("h", height); + objInfo.put("w", width); + //objInfo.put("orientation", 0); reqParams.put("info", objInfo); - reqParams.put("msgtype", "m.file"); - reqParams.put("body", file.getName()+".jpg"); + reqParams.put("msgtype", "m.image"); + reqParams.put("body", file.getName()); reqParams.put("url", uriFile); risposta = RequestHandler.postRequestJSON(requestUrl, reqParams); diff --git a/src/com/em/miguelbridge/botmatrix/RequestHandler.java b/src/com/em/miguelbridge/botmatrix/RequestHandler.java index 977461a..3df9cbc 100644 --- a/src/com/em/miguelbridge/botmatrix/RequestHandler.java +++ b/src/com/em/miguelbridge/botmatrix/RequestHandler.java @@ -72,7 +72,7 @@ public class RequestHandler { public static String[] postRequestFile(String inUrl, File file) throws IOException { CloseableHttpClient httpClient = HttpClients.createDefault(); HttpPost httpPost = new HttpPost(inUrl); - httpPost.setHeader("Content-Type", "application/file"); + httpPost.setHeader("Content-Type", "image/jpeg"); byte[] b = new byte[(int) file.length()]; FileInputStream fileInputStream = new FileInputStream(file); diff --git a/src/test/UploadTest.java b/src/test/UploadTest.java index 783e365..45aaeea 100644 --- a/src/test/UploadTest.java +++ b/src/test/UploadTest.java @@ -44,7 +44,7 @@ public class UploadTest { MatrixBot bot = new MatrixBot(); String token = bot.login(); bot.setAccessToken(token); - File file = new File("prova.png"); + File file = new File("prova.jpg"); //bot.sendMessage("provaa", "!mPkXwqjuGdhEVSopiG:maxwell.ydns.eu"); System.out.println(bot.sendFile("!mPkXwqjuGdhEVSopiG:maxwell.ydns.eu", file));