1
1
mirror of https://github.com/ahabhyde/miguelbridge synced 2025-01-10 14:34:21 +01:00

Immagini tg -> matrix inviate come immagini

Non vengono inviate se su tg viene inviata un'immagine già presente (problema nel trovare il path dell'immagine?)
This commit is contained in:
Ahab Hyde 2018-04-21 22:36:07 +02:00
parent c7b81d01c3
commit 53e3cce3d9
5 changed files with 22 additions and 5 deletions

BIN
image.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

BIN
prova.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 130 KiB

View File

@ -2,6 +2,7 @@ package com.em.miguelbridge.botmatrix;
import com.em.miguelbridge.Launcher; import com.em.miguelbridge.Launcher;
import java.awt.image.BufferedImage;
import java.io.*; import java.io.*;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URLEncoder; import java.net.URLEncoder;
@ -9,6 +10,8 @@ import java.net.URLEncoder;
import org.json.simple.*; import org.json.simple.*;
import org.json.simple.parser.*; import org.json.simple.parser.*;
import javax.imageio.ImageIO;
/** /**
* @author Emanuele Magon * @author Emanuele Magon
*/ */
@ -139,13 +142,27 @@ public class MatrixBot {
JSONObject reqParams = new JSONObject(); JSONObject reqParams = new JSONObject();
JSONObject objInfo = 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("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("info", objInfo);
reqParams.put("msgtype", "m.file"); reqParams.put("msgtype", "m.image");
reqParams.put("body", file.getName()+".jpg"); reqParams.put("body", file.getName());
reqParams.put("url", uriFile); reqParams.put("url", uriFile);
risposta = RequestHandler.postRequestJSON(requestUrl, reqParams); risposta = RequestHandler.postRequestJSON(requestUrl, reqParams);

View File

@ -72,7 +72,7 @@ public class RequestHandler {
public static String[] postRequestFile(String inUrl, File file) throws IOException { public static String[] postRequestFile(String inUrl, File file) throws IOException {
CloseableHttpClient httpClient = HttpClients.createDefault(); CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(inUrl); HttpPost httpPost = new HttpPost(inUrl);
httpPost.setHeader("Content-Type", "application/file"); httpPost.setHeader("Content-Type", "image/jpeg");
byte[] b = new byte[(int) file.length()]; byte[] b = new byte[(int) file.length()];
FileInputStream fileInputStream = new FileInputStream(file); FileInputStream fileInputStream = new FileInputStream(file);

View File

@ -44,7 +44,7 @@ public class UploadTest {
MatrixBot bot = new MatrixBot(); MatrixBot bot = new MatrixBot();
String token = bot.login(); String token = bot.login();
bot.setAccessToken(token); bot.setAccessToken(token);
File file = new File("prova.png"); File file = new File("prova.jpg");
//bot.sendMessage("provaa", "!mPkXwqjuGdhEVSopiG:maxwell.ydns.eu"); //bot.sendMessage("provaa", "!mPkXwqjuGdhEVSopiG:maxwell.ydns.eu");
System.out.println(bot.sendFile("!mPkXwqjuGdhEVSopiG:maxwell.ydns.eu", file)); System.out.println(bot.sendFile("!mPkXwqjuGdhEVSopiG:maxwell.ydns.eu", file));