Trouble uploading image

Skip to first unread message

Mohamed Faliq

Sep 25, 2021, 12:49:41 AMSep 25
to astrometry
So Im writing my own client in Java and Im running into an issue
Im trying to upload my image but I keep getting
{"status": "error", "errormessage": "no json"}

Im pretty certain it might be the encoding of my image. Attached is the file with the full encoding in base64. what Im not so sure about is do I encode it into a String or byte array? 
block of code thats doing the image encoding:
BufferedImage sourceimage = File(path));
ByteArrayOutputStream baos = new ByteArrayOutputStream();

ImageIO.write(sourceimage, "png", baos);
byte[] bytes = baos.toByteArray();    
String s = Base64.getEncoder().encodeToString(bytes);

Incase youre wondering this is my header
HttpURLConnection con = (HttpURLConnection)url.openConnection();
if (getSession() != null) {
con.setRequestProperty("Content-Type","multipart/form-data ; boundary="+boundary.toString());
con.setRequestProperty("Accept", "application/json");

Mohamed Faliq

Sep 25, 2021, 12:54:04 AMSep 25
to astrometry
I thought I should include what the whole process looks like
{"status": "success", "message": "authenticated user:", "session": "gd2okpgk3u8ikenf7m05wuzk4cryk2yh"}
end of request
MIME-Version: 1.0
Content-disposition: form-data; name="request-json"

Content-Type: application/octet-stream
MIME-Version: 1.0
Content-disposition: form-data; name="file"; filename=1.png

VBORw0KGgoAAAANSUhEUgAACNwAAA/ACAYAAAAjxZzNAA...shorten for your sanity

{"status": "error", "errormessage": "no json"}
end of request

Dustin Lang

Sep 25, 2021, 7:33:23 AMSep 25
to Mohamed Faliq, astrometry

I don't think you need to base-64 encode the data; you said the content-type was octet-stream.

But I don't think that is the issue with the error message you're getting.

Are you sure that the multipart messages have the correct '\r\n' line endings?  (see the python client and the HTML4 forms specification,

I have never used it (or looked at the code), but when I searched this forum I saw mentioned the JANclient, a Java client:
(last updated 5 years ago)

(Oh, I had a quick look at the code, and they're using the "import org.apache.http.entity.mime.MultipartEntity;" library to do the multipart-message encoding.)


You received this message because you are subscribed to the Google Groups "astrometry" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit

Dustin Lang

Sep 25, 2021, 7:34:46 AMSep 25
to Mohamed Faliq, astrometry
Oh, and, I don't know if this helps you, but the expected format is exactly what a web browser would send with an HTML form containing one text box (named "request-json") and one file upload element (named "file").
Reply all
Reply to author
0 new messages