mirror of
https://github.com/ahabhyde/miguelbridge
synced 2025-01-10 06:24:20 +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:
parent
c7b81d01c3
commit
53e3cce3d9
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user