Skip to content

Commit 6ceee04

Browse files
Jorge Fernandez Hernandezbsipocz
authored andcommitted
EUCLIDPCR-1971 Unable to upload user table from fits file
1 parent 1ebd810 commit 6ceee04

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

astroquery/utils/tap/core.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,7 @@ def upload_table(self, *, upload_resource=None, table_name=None, table_descripti
13411341
resource temporary table name associated to the uploaded resource
13421342
table_description : str, optional, default None
13431343
table description
1344-
format : str, optional, default 'VOTable'
1344+
format : str, optional, default 'votable'
13451345
resource format
13461346
verbose : bool, optional, default 'False'
13471347
flag to display information about the process
@@ -1381,9 +1381,7 @@ def upload_table(self, *, upload_resource=None, table_name=None, table_descripti
13811381
log.info(f"Uploaded table '{table_name}'.")
13821382
return None
13831383

1384-
def __uploadTableMultipart(self, resource, *, table_name=None,
1385-
table_description=None,
1386-
resource_format="VOTable",
1384+
def __uploadTableMultipart(self, resource, *, table_name=None, table_description=None, resource_format="votable",
13871385
verbose=False):
13881386
connHandler = self.__getconnhandler()
13891387
if isinstance(resource, Table):
@@ -1397,24 +1395,34 @@ def __uploadTableMultipart(self, resource, *, table_name=None,
13971395
fh = tempfile.NamedTemporaryFile(delete=False)
13981396
resource.write(fh, format='votable')
13991397
fh.close()
1400-
f = open(fh.name, "r")
1401-
chunk = f.read()
1402-
f.close()
1398+
1399+
with open(fh.name, "r") as f:
1400+
chunk = f.read()
1401+
14031402
os.unlink(fh.name)
14041403
files = [['FILE', 'pytable', chunk]]
1405-
contentType, body = connHandler.encode_multipart(args, files)
1404+
content_type, body = connHandler.encode_multipart(args, files)
14061405
else:
14071406
if not (str(resource).startswith("http")): # upload from file
14081407
args = {
14091408
"TASKID": str(-1),
14101409
"TABLE_NAME": str(table_name),
14111410
"TABLE_DESC": str(table_description),
1412-
"FORMAT": str(resource_format)}
1411+
"FORMAT": 'votable'}
14131412
log.info(f"Sending file: {resource}")
1414-
with open(resource, "r") as f:
1413+
1414+
t = Table.read(str(resource) )
1415+
fh = tempfile.NamedTemporaryFile(delete=False)
1416+
t.write(fh, format='votable')
1417+
fh.close()
1418+
1419+
with open(fh.name, "r") as f:
14151420
chunk = f.read()
1416-
files = [['FILE', os.path.basename(resource), chunk]]
1417-
contentType, body = connHandler.encode_multipart(args, files)
1421+
1422+
os.unlink(fh.name)
1423+
files = [['FILE', 'pytable', chunk]]
1424+
1425+
content_type, body = connHandler.encode_multipart(args, files)
14181426
else: # upload from URL
14191427
args = {
14201428
"TASKID": str(-1),
@@ -1423,8 +1431,8 @@ def __uploadTableMultipart(self, resource, *, table_name=None,
14231431
"FORMAT": str(resource_format),
14241432
"URL": str(resource)}
14251433
files = [['FILE', "", ""]]
1426-
contentType, body = connHandler.encode_multipart(args, files)
1427-
response = connHandler.execute_upload(body, contentType)
1434+
content_type, body = connHandler.encode_multipart(args, files)
1435+
response = connHandler.execute_upload(body, content_type)
14281436
if verbose:
14291437
print(response.status, response.reason)
14301438
print(response.getheaders())

docs/esa/euclid/euclid.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,9 @@ surrounded by quotation marks, i.e.: *user_<your_login_name>."<table_name>"*):
863863
2.5.2. Uploading table from file
864864
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
865865

866-
A file containing a table (votable, fits or csv) can be uploaded to the user's private area.
866+
A file containing a table can be uploaded to the user private area. Only the formats described https://docs.astropy.org/en/stable/io/unified.html#built-in-table-readers-writers,
867+
and automatically identified by its suffix or content can be used. Note that for a multi-extension fits file with multiple
868+
tables, the first table found will be read.
867869

868870
The parameter 'format' must be provided when the input file is not a votable file.
869871

docs/gaia/gaia.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,9 @@ surrounded by quotation marks, i.e.: *user_<your_login_name>."<table_name>"*)::
581581
2.3.2. Uploading table from file
582582
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
583583

584-
A file containing a table (votable, fits or csv) can be uploaded to the user private area.
584+
A file containing a table can be uploaded to the user private area. Only the formats described https://docs.astropy.org/en/stable/io/unified.html#built-in-table-readers-writers,
585+
and automatically identified by its suffix or content can be used. Note that for a multi-extension fits file with multiple
586+
tables, the first table found will be read.
585587

586588
The parameter 'format' must be provided when the input file is not a votable file.
587589

@@ -665,7 +667,7 @@ A table from the user private area can be deleted as follows::
665667

666668
>>> from astroquery.gaia import Gaia
667669
>>> Gaia.login_gui()
668-
>>> job = Gaia.delete_user_table("table_test_from_file")
670+
>>> job = Gaia.delete_user_table(table_name="table_test_from_file")
669671
Table 'table_test_from_file' deleted.
670672

671673
2.5. Updating table metadata

0 commit comments

Comments
 (0)