Hello Konrad,
You may need to replace the following line,
{"id": str(uuid.uuid4()), "name": "FREIAlogo-v3_March19.png"}
with
{"id": str(uuid.uuid4()), "filename": "FREIAlogo-v3_March19.png"}
which means the "filename" keyword rather than "name" keyword should be used.
Attached is the test code which can upload one file successfully in my test environment.
Regards,
Lin
> -----原始邮件-----
> 发件人: "Konrad Gajewski via Tech-talk" <tech-talk at aps.anl.gov>
> 发送时间:2024-04-08 19:51:29 (星期一)
> 收件人: "tech-talk at aps.anl.gov" <tech-talk at aps.anl.gov>
> 主题: [SPAM] Use of PUT https://urldefense.us/v3/__https://localhost:8181/Olog/logs/multipart__;!!G_uCfscf7eWS!ZWzrzroyYSbP9vfWkqeX932CPkasA0QSuJ0MFTQCpyUwqMaA3e8M3XWhhpiUrbgPnf00JJj9l7oi4sToNK8HVis$ REST API for creating log entries with attachments
>
> Hi,
>
> I'm trying to write a simple python program to create an entry in the
> new Olog server (API documented in
> https://urldefense.us/v3/__https://olog.readthedocs.io/en/latest/index.html__;!!G_uCfscf7eWS!dDgYNelpLq7ymQ7M1rIdPoepGvVQEAfQPCBtmSKeFTIOr5xieb6nu3QDLfhW7gWC1u9P52dP1-w0PfTS-T4BhX99ax7hhJoQQa75$ ).
>
> I am using PUT https://urldefense.us/v3/__https://localhost:8181/Olog/logs/multipart__;!!G_uCfscf7eWS!dDgYNelpLq7ymQ7M1rIdPoepGvVQEAfQPCBtmSKeFTIOr5xieb6nu3QDLfhW7gWC1u9P52dP1-w0PfTS-T4BhX99ax7hhOZ21DPF$ request and
> all works fine for entries without any attachments. If I try to add an
> attachment the entry itself is saved but saving the attachment fails.
>
> I have found pyOlog library but it seems to be the old version written
> for Glassfish and mysql architecture.
>
> Does anybody have a python library, or at least an example program
> showing how to use the new PUT
> https://urldefense.us/v3/__https://localhost:8181/Olog/logs/multipart__;!!G_uCfscf7eWS!dDgYNelpLq7ymQ7M1rIdPoepGvVQEAfQPCBtmSKeFTIOr5xieb6nu3QDLfhW7gWC1u9P52dP1-w0PfTS-T4BhX99ax7hhOZ21DPF$ API for creating the entries
> with an attachment. A curl command showing the use of PUT
> https://urldefense.us/v3/__https://localhost:8181/Olog/logs/multipart__;!!G_uCfscf7eWS!dDgYNelpLq7ymQ7M1rIdPoepGvVQEAfQPCBtmSKeFTIOr5xieb6nu3QDLfhW7gWC1u9P52dP1-w0PfTS-T4BhX99ax7hhOZ21DPF$ would also be helpful.
>
> Below is the python code that I've used:
>
> api_endpoint = "https://urldefense.us/v3/__https://olog-server:8181/Olog/logs/multipart__;!!G_uCfscf7eWS!dDgYNelpLq7ymQ7M1rIdPoepGvVQEAfQPCBtmSKeFTIOr5xieb6nu3QDLfhW7gWC1u9P52dP1-w0PfTS-T4BhX99ax7hhJIczIfa$ "
>
> # Prepare log entry payload
> log_entry = {
> "owner": "dev",
> "description": "New entry using Olog/logs/multipart with one
> attachment.\n",
> "level": "INFO",
> "title": "test4.py",
> "logbooks": [{"name": "test"}],
> "attachments":[
> {"id": str(uuid.uuid4()), "name": "FREIAlogo-v3_March19.png"}
> ]
> }
>
> # Prepare the log entry payload as JSON
> json_data = json.dumps(log_entry)
> json_filename = json.dumps({"filename": "FREIAlogo-v3_March19.png"})
> json_descr = json.dumps({"fileMetadataDescription": "image/png"})
>
> # Prepare the multipart encoder
> multipart_data = MultipartEncoder(
> fields={
> 'logEntry': ('logEntry.json', json_data, 'application/json'),
> 'files': ('filename', json_filename, 'application/json'),
> 'files': ('fileMetadataDescription', json_descr,
> 'application/json'),
> 'files': ('FREIAlogo-v3_March19.png',
> open('FREIAlogo-v3_March19.png', 'rb'), 'application/octet-stream')
> }
> )
>
> # Set the Content-Type header with the boundary
> headers = {
> 'Content-Type': multipart_data.content_type
> }
> try:
> response = requests.put(api_endpoint, headers=headers,
> data=multipart_data, auth=HTTPBasicAuth(username, password))
> if response.status_code == 200:
> print("Log entry created successfully.")
> else:
> print("Failed to create log entry. Status code:
> {response.status_code}")
> except Exception as e:
> print("An error occurred: ",{str(e)})
>
> And a log from phoebus-olog server:
>
> 2024-04-08 13:28:42.337 DEBUG 1740 --- [nio-8181-exec-4]
> o.s.web.servlet.DispatcherServlet : PUT "/Olog/logs/multipart",
> parameters={multipart}
> 2024-04-08 13:28:42.347 DEBUG 1740 --- [nio-8181-exec-4]
> s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to
> org.phoebus.olog.LogResource#createLog(String, String, String, Log,
> MultipartFile[], Principal)
> 2024-04-08 13:28:42.349 DEBUG 1740 --- [nio-8181-exec-4]
> .m.m.a.RequestPartMethodArgumentResolver : Read "application/json" to
> [org.phoebus.olog.entity.Log@c517dec8]
> 2024-04-08 13:28:42.404 INFO 1740 --- [nio-8181-exec-4]
> org.phoebus.olog.LogResource : Entry id 75 created from n/a
> 2024-04-08 13:28:42.406 WARN 1740 --- [nio-8181-exec-4]
> org.phoebus.olog.LogResource : File FREIAlogo-v3_March19.png
> not matched with attachment meta-data
> 2024-04-08 13:28:42.407 INFO 1740 --- [nio-8181-exec-4]
> org.phoebus.olog.LogResource : Entry id 75 created from n/a
> 2024-04-08 13:28:42.408 DEBUG 1740 --- [nio-8181-exec-4]
> m.m.a.RequestResponseBodyMethodProcessor : Using 'application/json',
> given [*/*] and supported [application/json, application/*+json,
> application/json, application/*+json]
> 2024-04-08 13:28:42.408 DEBUG 1740 --- [nio-8181-exec-4]
> m.m.a.RequestResponseBodyMethodProcessor : Writing
> [org.phoebus.olog.entity.Log@ff3dfa85]
> 2024-04-08 13:28:42.410 DEBUG 1740 --- [nio-8181-exec-4]
> o.s.web.servlet.DispatcherServlet : Completed 200 OK
>
> Best regards,
> Konrad
>
> --
> Konrad Gajewski
> FREIA Laboratory
> https://urldefense.us/v3/__http://www.physics.uu.se/__;!!G_uCfscf7eWS!dDgYNelpLq7ymQ7M1rIdPoepGvVQEAfQPCBtmSKeFTIOr5xieb6nu3QDLfhW7gWC1u9P52dP1-w0PfTS-T4BhX99ax7hhPzk46FZ$
>
>
>
>
>
>
>
>
>
> När du har kontakt med oss på Uppsala universitet med e-post så innebär det att vi behandlar dina personuppgifter. För att läsa mer om hur vi gör det kan du läsa här: https://urldefense.us/v3/__http://www.uu.se/om-uu/dataskydd-personuppgifter/__;!!G_uCfscf7eWS!dDgYNelpLq7ymQ7M1rIdPoepGvVQEAfQPCBtmSKeFTIOr5xieb6nu3QDLfhW7gWC1u9P52dP1-w0PfTS-T4BhX99ax7hhEJJRf56$
>
> E-mailing Uppsala University means that we will process your personal data. For more information on how this is performed, please read here: https://urldefense.us/v3/__http://www.uu.se/en/about-uu/data-protection-policy__;!!G_uCfscf7eWS!dDgYNelpLq7ymQ7M1rIdPoepGvVQEAfQPCBtmSKeFTIOr5xieb6nu3QDLfhW7gWC1u9P52dP1-w0PfTS-T4BhX99ax7hhIzZpdTb$
Attachment:
test2.py
Description: Binary data
- Replies:
- Re: Use of PUT https://localhost:8181/Olog/logs/multipart REST API for creating log entries with attachments Konrad Gajewski via Tech-talk
- References:
- Use of PUT https://localhost:8181/Olog/logs/multipart REST API for creating log entries with attachments Konrad Gajewski via Tech-talk
- Navigate by Date:
- Prev:
Re: Use of PUT https://localhost:8181/Olog/logs/multipart REST API for creating log entries with attachments Shroff, Kunal via Tech-talk
- Next:
Check for write access in EPICS 7 Bellister, ,Jesse via Tech-talk
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
<2024>
2025
- Navigate by Thread:
- Prev:
Re: Use of PUT https://localhost:8181/Olog/logs/multipart REST API for creating log entries with attachments Shroff, Kunal via Tech-talk
- Next:
Re: Use of PUT https://localhost:8181/Olog/logs/multipart REST API for creating log entries with attachments Konrad Gajewski via Tech-talk
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
<2024>
2025
|