Hello! I have been trying to upload a annotation via API lately, but it always return that the annotation format is unsupported, even if i upload a exported annotation from existing images.
Are there more guidelines then what is written in the guide page?
Welcome to the forum! Sorry to hear you’re having issues with the annotate API.
We don’t yet have more documentation for this beyond the annotate via api docs but I’m happy to help. Could you share more info about the API request (ideally a code snippet) and the annotation format you’re uploading?
If you could send me an example image & annotation I’d be happy to test on my side; it’s possible you’re encountering a bug but without more info it’s hard to say.
Once we figure things out we’ll be sure to update the docs to help future readers avoid this problem!
upload_url = "".join([
f"https://api.roboflow.com/dataset/{datasetname}/annotate/{pic_id}",
"?api_key=mykey",
"&name=", f"6.xml"
])
# POST to the API
r = requests.post(upload_url, data=annotation_str, headers={
"Content-Type": "text/plaintext"
})
# Output result
return r.json()
def _uploadimg(img,picname, datasetname=‘mydb’):
image = img
if not isinstance(img,Image.Image):
# Load Image with PIL
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
image = Image.fromarray(img)
# Convert to JPEG Buffer
buffered = io.BytesIO()
image.save(buffered, quality=90, format="JPEG")
# Base 64 Encode
img_str = base64.b64encode(buffered.getvalue())
img_str = img_str.decode("ascii")
# Construct the URL
upload_url = "".join([
f"https://api.roboflow.com/dataset/{datasetname}/upload",
"?api_key=mykey",
f"&name={picname}",
"&split=train"
])
# POST to the API
r = requests.post(upload_url, data=img_str, headers={
"Content-Type": "application/x-www-form-urlencoded"
})
return json.loads(r.content).get('id',None)
def test():
im = PIL.Image.open(“images_png.rf.7c0985eb122fe55a1b9b030f551eb211.jpg”)
picid = _uploadimg(im,“test.jpg”,“mydb”)
ano = open(“images_png.rf.7c0985eb122fe55a1b9b030f551eb211.xml”,“r”).read()
annotation = _uploadannotation(ano,picid,“images_png.rf.7c0985eb122fe55a1b9b030f551eb211.jpg”,“mydb”)
pass
Could you retry with the Content-Type header as text/plain instead of text/xml? I believe we use the name= query param to infer the type vs the Content-Type; it might be confusing our body parser.
Many thanks! , I hope this issue can be reproduced easily, if any additional information is necessary or the result cannot be reproduced, I will write a full standalone code to ensure the reproducibility of the issue
I tested some more variation on the uploading process and it turns out, if i use the filename “6.xml” or “6.txt”. Then the upload of anotation will fail, but with something such as “test.xml” or “test.txt” it works correctly, for now.
I’m unsure if I just missed it completely or it was working a few days ago, but by modifying the code snippet above from ‘6.xml’ to ‘test.xml’ solved my issue, the ‘text/plaintext’ or ‘text/xml’ doesn’t affect the calls as for now.