-
-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding an attachment via API doesn't work #502
Comments
Digging through the API further I thought of another way to add an attachment: By posting a PATCH request to a part directly, but that also does not work. It always returns Here's an example, this time more simple with cURL:
Result
|
…eir owning elemens as direct POST operations are not possible yet This partly fixes issue #502
The main problem, is that attachments (similar to parameters) can belong to different elements, and there are different classes to model that. However when trying to create a new attachment via POST, it can not be decided, which class to instantiate and this error occurs. I think this is not quite an easy fix and it might require some changes to the current API interface. I will look into that in the future. For now as an workaround, at least the possibility to create new attachments (and parameters) via the PATCH operation should work now with something like:
See here for more infos: https://docs.part-db.de/api/intro.html#creating-attachments-and-parameters |
Thank you for fixing this so quickly. It works, but when I add attachments like this it creates external links. I'd like to save all files locally, so I tried to add My .env.local says
|
Currently its not possible to upload files via API and its also not possible to let Part-DB download files. |
Okay. 😕 |
It's not "intended" by me, but that's what the json merge specification says, and how the API framework works. I tried out some stuff, and there seems to be no possibility to just refer existing elements. Therefore I would only recommend to use PATCH to change scalar values on elements, not such nested stuff. However that's currently the only way to properly create new attachments. If you really need to add additional attachments to an element with existing ones, then it should work with the following workaround: Retrieve the current attachments of an element, store them somewhere. Then send an patch response with an empty array, to remove all existing attachments on the element (to prevent validation errors). Then send a patch array with containing the old attachments, and your new ones. This will recreate the attachments. You will loose Infos like creation date, last modified and history. And it will only work if they contain an URL. You will not be able to recreate attachments containing a local file via API yet. Depending on what you currently try to achieve, maybe directly accessing and modifying the database of Part-DB directly might be the better choice for now |
The merge behavior is not a major issue. I wrote a script that converted my LCSC orders into Part-DB compatible CSV files. That worked fine, but they also have actual photos of each part and datasheets for most parts on their website, so I'd like to scrape those off their servers and store them in Part-DB. That said, my parts don't have any attachments that I'd lose and could not recover, but having them locally is important to me. Since it's - more or less - a one-off task, I'll probably create the database entries via API and then take your advice, download the files myself and modify the rows in the database. |
…ters based on the chosen element IRI Related to issue #502
With the latest commits, the POST endpoint for attachments and parameters work fine. The attachment type is normally autodetected on the IRI of the So no need for this weird workaround anymore. |
Describe the bug
I'm trying to add an attachment to a component via API and no matter how I'm sending my data, I always get an error 500 back
To Reproduce
This is a very simple example written in Python
Expected behavior
A new attachment for part 212
Screenshots
Result looks like this:
Server Side
Script host
Additional context
Since the example in the API documentation is throwing the same error, I'm opening this as a bug, but if I'm just missing some key element in my JSON, some heads up would be nice.
var/log/prod.log reports a bunch of lines, but I think this one looks most helpful
The text was updated successfully, but these errors were encountered: