Closed Nath5 closed 3 weeks ago
After some more digging it looks like the problem is more specifically in this function:
public static String uploadPicture(@NotNull InputStream in, @NotNull String token) throws IOException {
String uploadId = Long.toString(Math.abs((new Random()).nextLong()), 36);
byte[] bytes = new byte[in.available()];
in.read(bytes);
boolean isCookie = token.contains("sessionid");
Request.Builder uploadReq = (new Request.Builder()).url("https://i.instagram.com/rupload_igphoto/JxInsta_upload_" + uploadId).post(RequestBody.create(bytes)).headers(Headers.of(Constants.BASE_HEADERS)).addHeader("x-instagram-rupload-params", "{\"media_type\":1,\"upload_id\":\"" + uploadId + "\"}").addHeader("x-entity-length", String.valueOf(bytes.length)).addHeader("x-entity-name", "JxInsta_upload_" + uploadId).addHeader("x-entity-type", "image/jpeg").addHeader("offset", String.valueOf(0)).removeHeader("content-type").addHeader(isCookie ? "cookie" : "authorization", token).addHeader("content-type", "application/octet-stream");
Response res = client.newCall(uploadReq.build()).execute();
if (res.isSuccessful()) {
return uploadId;
} else {
System.out.println(res.body().string());
throw new IOException("Failed to upload picture");
}
}
Thanks for figuring it out :) I will look into this soon and will fix at ASAP.
I just tested and it's perfectly working fine. I think the problem is in your image input-stream. Try doing same with a local image using FileInputStream
Error while trying to post a picture. Error message and example code are below.
Library Version: JxInsta-v1.0-beta-2.jar Java Version: 17
{"debug_info":{"retriable":false,"type":"ProcessingFailedError","message":"{\"message\":\"Handle is missing.\",\"status\":\"fail\"}"}}