-
Notifications
You must be signed in to change notification settings - Fork 8
Media management
In LumApps you can upload medias (pictures, documents ...) and find them under the media
section in the admin panel.
An uploaded media can be used to illustrate a content, add as a thumbnail, be featured in a media-list widget...
The first things you need is your media as a bytes object in python
my_media = <your_media_as_bytes>
The second step is to request an upload url to LumApps in order for you to upload the given media.
To do that you will need to call the document/uploadUrl/get
endpoints.
Important Notes
- In LumApps the location where a media is stored in given by what's called a
docPath
that is of the formprovider=<a_provider>/site=<a_lumapps_site_di>/resource=<a_lumapps_media_id>
. In order for you do pretty much anything with media via api you need to know this docPath or you need to know how to construct it.For more infos see the media docPath section - A media is also associated with a sort of 'scope', that is you define if the media should be shared (ie, visible by everyone in the library) or not. This is done via the
isShared
parameter when you upload the media. Note that the sharing is done based on the user who make the upload request.
api = ....
body = {
"fileName": <your_filename>,
"lang": <the_lang_of_the_file>,
"parentPath": <you_doc_path_within_lumapps>,
"shared": <wether_your_media_is_shared_or_not>,
"success": "/upload",
}
upload_infos = api.get_call("document/uploadUrl/get", body=body)
upload_url = upload_infos["uploadUrl"]
The last thing is to upload the media data you stored in step 1. This is done via a simple form upload.
files_tuple_list = [
("files", (<your_filename>, my_media, <you_file_mimeType>]))
]
response = api.file_upload_session.post(
upload_url,
headers={"Authorization": "Bearer " + api.token}, # For authorization reasons
files=files_tuple_list,
)
if response.status_code == 200:
files = response.json()
if files.get("items"):
new_media = files["items"][0]
Here you have, if all goes well the new_media should contained the LumApps media object returned by the successfull upload.
Because the medias can be stored in folders, subfolders ... the docPath can be a bit cimplicated to understand
- Base
The basis is provider=<a_provider>/site=<a_lumapps_site_id>
, with that docPath the media will be saved in the root folder of the media of the precised site.
- With folder
If you want to upload it in a folder, you will need the folder id
and add it as the resource
For instance if I want to upload a media to the folder with the id 183097498
my docPath will be
my_doc_path=provider=local/site=97748071/resource=183097498