Trouble uploading image

18 views
Skip to first unread message

Mohamed Faliq

unread,
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 = ImageIO.read(new 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();
con.setRequestMethod("POST");
if (getSession() != null) {
//header
con.setRequestProperty("Content-Type","multipart/form-data ; boundary="+boundary.toString());
}
con.setRequestProperty("Accept", "application/json");
con.setDoOutput(true);

Mohamed Faliq

unread,
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: mohamed...@gmail.com", "session": "gd2okpgk3u8ikenf7m05wuzk4cryk2yh"}
end of request
--===============2710248805955031976==
Content-Type:text/plain  
MIME-Version: 1.0
Content-disposition: form-data; name="request-json"

{"allow_commercial_use":"d","allow_modifications":"d","publicly_visible":"y","session":"gd2okpgk3u8ikenf7m05wuzk4cryk2yh"}
--===============2710248805955031976==
Content-Type: application/octet-stream
MIME-Version: 1.0
Content-disposition: form-data; name="file"; filename=1.png

VBORw0KGgoAAAANSUhEUgAACNwAAA/ACAYAAAAjxZzNAA...shorten for your sanity
--===============2710248805955031976==--

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


Dustin Lang

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

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 https://github.com/dstndstn/astrometry.net/blob/main/net/client/client.py#L76) and the HTML4 forms specification, https://www.w3.org/TR/html401/interact/forms.html#h-17.13.4

I have never used it (or looked at the code), but when I searched this forum I saw mentioned the JANclient, a Java client: http://www.tecde.homepage.t-online.de/software/Astrometry.html
(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.)

cheers,
--dustin



--
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 astrometry+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/astrometry/8f21e243-4983-475f-ac28-6b67e14a6bd2n%40googlegroups.com.

Dustin Lang

unread,
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
Forward
0 new messages