Skip to content

Commit aadeffe

Browse files
readme: add note to replacing master file
1 parent 64395cf commit aadeffe

1 file changed

Lines changed: 180 additions & 57 deletions

File tree

README.rst

Lines changed: 180 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@ Table of Contents
3434
- `Step 3: Upload the Video <#step-3-upload-the-video>`_
3535
- `Step 4: Create a Flow <#step-4-create-a-flow>`_
3636
- `Optional: Upload Additional File <#optional-upload-additional-file>`_
37-
- `Optional: Replace the Main Video File <#optional-replace-the-main-video-file>`_
3837
- `Optional: Update the Access of the Video <#optional-update-the-access-of-the-video>`_
3938
- `Step 5: Get Video to Check the Flow Status <#step-5-get-video-to-check-the-flow-status>`_
4039
- `Step 6: Publish Video <#step-6-publish-video>`_
40+
- `Replace the Main Video File through REST API <#replace-the-main-video-file-through-rest-api>`_
41+
- `General Flow <#general-flow>`_
42+
- `Alternative: Without Doing the Get Request <#alternative-without-doing-the-get-request>`_
4143

4244

4345
Prerequisites
@@ -625,62 +627,6 @@ Optional: Upload Additional File
625627
- To include the file in the body, modify the `pre-request script` in Bruno.
626628

627629

628-
Optional: Replace the Main Video File
629-
------------------------------------------
630-
631-
**1. Request:**
632-
633-
``PUT`` ``{{baseURL}}/api/files/{{bucket_id}}/{{main_video_key}}``
634-
635-
**Headers:**
636-
637-
- ``X-Invenio-File-Tags: times_replaced=number_of_times_replaced``
638-
639-
**Parameters:**
640-
641-
.. list-table::
642-
:header-rows: 1
643-
644-
* - **Name**
645-
- **Type**
646-
- **Location**
647-
- **Description**
648-
* - **bucket_id**
649-
- string
650-
- path
651-
- ID of the bucket to upload the file.
652-
* - **main_video_key**
653-
- string
654-
- path
655-
- Key of the previously uploaded main file.
656-
* - **file**
657-
- file
658-
- body
659-
- The file to be uploaded.
660-
661-
662-
- To include the file in the body, modify the `pre-request script` in Bruno.
663-
664-
**⚠️ Important**
665-
666-
You must use the exact ``key`` value from the response of the `Create a Flow <#step-4-create-a-flow>`_ request
667-
(stored as ``main_video_key``) to overwrite the existing file when replacing the main video.
668-
669-
This is required because the backend **renames the uploaded file** to distinguish it from automatically generated subformat files.
670-
Using the original file name (``video_name``) will not work for replacement.
671-
672-
Do **not** confuse this with the initial video upload request, which uses the original video file name (``video_name``).
673-
674-
**Response:**
675-
676-
Uploaded file JSON. Save ``response.body.version_id`` as ``main_file_version_id`` and ``response.body.key`` as ``video_key`` for later use.
677-
678-
**2. Request:**
679-
680-
Start the flow again using the new main video file, along with the updated ``main_file_version_id`` and ``video_key``.
681-
You can follow the same structure outlined in `Step 4 <#step-4-create-a-flow>`_.
682-
683-
684630
Optional: Update the Access of the Video
685631
----------------------------------------
686632

@@ -803,3 +749,180 @@ Before publishing the video, ensure that the workflow is complete.
803749

804750
Published video deposit JSON.
805751

752+
753+
Replace the Main Video File through REST API
754+
============================================
755+
756+
General Flow
757+
------------
758+
759+
1. Get the video (see `Step 5 <#step-5-get-video-to-check-the-flow-status>`_) and find the master file key from the response.
760+
761+
**Request:**
762+
763+
``GET {{baseURL}}/api/deposits/video/{{video_id}}``
764+
765+
**Headers:**
766+
767+
- ``content-type: application/vnd.project.partial+json``
768+
769+
**Parameters:**
770+
771+
.. list-table::
772+
:header-rows: 1
773+
774+
* - **Name**
775+
- **Type**
776+
- **Location**
777+
- **Description**
778+
* - **video_id**
779+
- string
780+
- path
781+
- ID of the video.
782+
783+
**Response:**
784+
785+
Video JSON. You can find the main file inside ``response.body.metadata._files``.
786+
787+
.. code-block:: javascript
788+
789+
let files = data.metadata?._files || [];
790+
// Find the master file
791+
let masterFile = files.find(f => f.context_type === "master");
792+
video_key = masterFile.key;
793+
794+
795+
2. Upload the new video with the same master key and same ``bucket_id`` (see `Step 3 <#step-3-upload-the-video>`_)
796+
797+
**Upload Request**
798+
799+
``PUT {{baseURL}}/api/files/{{bucket_id}}/{{main_video_key}}``
800+
801+
**Headers:**
802+
803+
- ``X-Invenio-File-Tags: times_replaced=number_of_times_replaced``
804+
805+
**Parameters:**
806+
807+
.. list-table::
808+
:header-rows: 1
809+
810+
* - **Name**
811+
- **Type**
812+
- **Location**
813+
- **Description**
814+
* - **bucket_id**
815+
- string
816+
- path
817+
- ID of the bucket to upload the file.
818+
* - **main_video_key**
819+
- string
820+
- path
821+
- Key of the previous main file.
822+
* - **file**
823+
- file
824+
- body
825+
- The file to be uploaded.
826+
827+
**Response:**
828+
829+
Uploaded file JSON. Save version_id and key for later use:
830+
831+
- ``response.body.version_id`` → ``version_id``
832+
- ``response.body.key`` → ``video_key``
833+
834+
835+
836+
3. Start the flow with your new ``video_key`` and ``version_id`` but keep the same ``bucket_id`` and ``deposit_id`` (see `Step 4 <#step-4-create-a-flow>`_)
837+
838+
**Request:**
839+
840+
``POST /api/flows/``
841+
842+
**Headers:**
843+
844+
- ``content-type: application/vnd.project.partial+json``
845+
846+
**Parameters:**
847+
848+
.. list-table::
849+
:header-rows: 1
850+
851+
* - **Name**
852+
- **Type**
853+
- **Location**
854+
- **Description**
855+
* - **version_id**
856+
- string
857+
- body
858+
- Version ID from the uploaded video response.
859+
* - **key**
860+
- string
861+
- body
862+
- Video key from the uploaded video response.
863+
* - **bucket_id**
864+
- string
865+
- body
866+
- Bucket ID from the Create Video response.
867+
* - **deposit_id**
868+
- string
869+
- body
870+
- Deposit ID from the Create Video response.
871+
872+
**Body:**
873+
874+
.. code-block:: json
875+
876+
{
877+
"version_id": "{{main_file_version_id}}",
878+
"key": "{{video_key}}",
879+
"bucket_id": "{{bucket_id}}",
880+
"deposit_id": "{{video_id}}"
881+
}
882+
883+
884+
Alternative: Without Doing the Get Request
885+
------------------------------------------
886+
887+
If you want to integrate this process into your workflow **without calling the Get Video request**,
888+
you must be careful about which **video key** you are using, since it changes during different stages.
889+
890+
**⚠️ Important: Using the Correct Video Key**
891+
892+
The ``video_key`` changes and you must use the correct key depending on when you're performing the replacement:
893+
894+
- **Scenario 1: Replacing after initial file upload (before creating flow)**
895+
896+
- Use the ``video_key`` returned from the upload file request response.
897+
898+
- **Scenario 2: Replacing after creating the flow (before publishing)**
899+
900+
- Use the ``key`` value from the Create Flow response.
901+
902+
This is required because the backend **renames the uploaded file** to distinguish it from automatically generated subformat files.
903+
904+
- **Scenario 3: Replacing after publishing the video**
905+
906+
- First make an edit request to modify the published video.
907+
908+
- ``POST {{baseURL}}/api/deposits/video/{{deposit_id}}/actions/edit``
909+
910+
- Find the master file key from the response:
911+
912+
.. code-block:: javascript
913+
914+
let files = data.metadata?._files || [];
915+
// Find the master file
916+
let masterFile = files.find(f => f.context_type === "master");
917+
video_key = masterFile.key;
918+
919+
- Use this ``video_key`` for the replacement request.
920+
921+
922+
Do **not** use the original video file name (``video_name``) for replacement requests,
923+
as this will not work due to the backend file renaming process.
924+
925+
After finding the correct key, you can upload your new file (see `Step 3 <#step-3-upload-the-video>`_).
926+
927+
Then, start the flow again using the new main video file, along with the updated ``version_id`` and ``video_key``.
928+
You can follow the same structure outlined in `Step 4 <#step-4-create-a-flow>`_.

0 commit comments

Comments
 (0)