File upload doesn't really work from my C#.NET client app

65 views
Skip to first unread message

László Heller

unread,
Oct 23, 2019, 5:49:36 AM10/23/19
to astrometry
Hi!

I am trying to write a client using the nova.astrometry.net API in C#.NET.
Authentication works well, I can easily obtain session ID for my API key.

However when I want to upload an image using the /api/upload endpoint described here, the server response is following:
HTTP/1.1 200 OK
Date: Wed, 23 Oct 2019 09:36:28 GMT
Server: Apache/2.4.18 (Ubuntu) mod_wsgi/4.3.0 Python/2.7.12
Content-Length: 46
Access-Control-Allow-Origin: *
Content-Type: text/plain; charset=UTF-8

{"status": "error", "errormessage": "no json"}

My request (also attached as a text file) is following:
POST http://nova.astrometry.net/api/upload HTTP/1.1
Content-Type: multipart/form-data; boundary=---------------------------0b386c5a-e33a-4db4-bbd9-a5229090ccee
Host: nova.astrometry.net
Content-Length: 781078
Expect: 100-continue

-----------------------------0b386c5a-e33a-4db4-bbd9-a5229090ccee
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": "0gihhfytvh1o7ajf1rrt55ynhha38y22"}
-----------------------------0b386c5a-e33a-4db4-bbd9-a5229090ccee
Content-Type: application/octet-stream
MIME
-Version: 1.0
Content-disposition: form-data; name="file"; filename="66011311_10214710726185818_2918331987305431040_o.jpg"

<ISO-8859-1 ENCODED JPEG FILE CONTENT>
-----------------------------0b386c5a-e33a-4db4-bbd9-a5229090ccee--

Any idea, why I am receiving Error - No JSON in the response?

BR,

Ladislav
RawFile.txt

Dustin Lang

unread,
Oct 23, 2019, 8:28:39 AM10/23/19
to László Heller, astrometry
It looks like you have "request - json" but it must be "request-json"  -- no spaces.


--
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/3ae108c6-eae4-4def-b6e0-bfd567ebc854%40googlegroups.com.

László Heller

unread,
Oct 23, 2019, 8:47:00 AM10/23/19
to astrometry
Hi!

You're right, but that was not the only problem.
I also incorrectly specified the value of Content-Type for request.

Wrong value:
Content-Type: multipart/form-data; boundary=---------------------------0b386c5a-e33a-4db4-bbd9-a5229090ccee

Correct value:
Content-Type: multipart/form-data; boundary="---------------------------0b386c5a-e33a-4db4-bbd9-a5229090ccee"

The boundary separator must be quoted!

The upload works well, but now I have another issue. No job is starting for submission (a JPEG image), because of the following (taken from my astrometry dashboard):
Unfortunately, we couldn't process this submission properly:

       
...get_or_create_image(df)
  File "process_submissions.py", line 586, in get_or_create_image
    img = create_source_list(df)
  File "process_submissions.py", line 673, in create_source_list
    raise e
TypeError: cannot perform reduce with flexible type

   
   

BR,

Ladislav
To unsubscribe from this group and stop receiving emails from it, send an email to astro...@googlegroups.com.

Dustin Lang

unread,
Oct 23, 2019, 8:48:54 AM10/23/19
to László Heller, astrometry
If you can try again and tell me the submission id, I can check the file contents that were uploaded.  Possibly your encoding is wrong.


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/2248d1d7-3a79-4629-a019-992838afb513%40googlegroups.com.

László Heller

unread,
Oct 23, 2019, 8:54:26 AM10/23/19
to astrometry
Hi!

Last submission ID is 3002549. I tried encodings ASCII, UTF8 and ISO-8859-1.

BR,

Ladislav

Dustin Lang

unread,
Oct 23, 2019, 9:09:37 AM10/23/19
to László Heller, astrometry
If you're uploading *data*, I don't think you should be using an encoding.  It's just an octet-stream, right?

Attached is the file we received.  Maybe this will help you sort out what went wrong.

By the way, the format is *exactly* what would be sent from a plain old HTML form with a text box named "request-json" and a file upload box.

cheers,
--dustin



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/f518bf19-1784-4917-8552-b789fe68c33f%40googlegroups.com.
c3e433e1ecb9b4e493811cb0635180af861214b1

László Heller

unread,
Oct 23, 2019, 11:04:26 AM10/23/19
to astrometry
Hi!

Again you're right, I don't need to use any encoding, just simple put the image file content as byte array to the second part of multipart request body. That's it, now it works!

Thanks for tips and best regards,

Ladislav
Reply all
Reply to author
Forward
0 new messages