Upload Media Files
Overview on how to configure a client for media files uploads
Last updated
Overview on how to configure a client for media files uploads
Last updated
Configuring a client to access the file storage service from the NxtFi API requires specific knowledge. Since the operation needs to be securely recorded in the blockchain without compromising computational power, certain actions must be taken on the client side to achieve this objective. The steps described below guarantee a fully transparent and efficient mechanism for uploading files up to 10 MB in size each.
Is good to remember that the client will need:
Obtain the necessary client credentials: Acquire the required credentials, such as authorized key-pair from the NxtFi API to authenticate the client.
Establish a secure connection: Configure the client to establish a secure connection with the NxtFi API endpoint using HTTPS.
Prepare the file for upload: Prior to uploading the file, ensure that it is properly prepared. This may involve validating the file format, checking for any restrictions on file types, and compressing the file if necessary. (At the moment any type is accepted up to 10MB for each call)
The first step after checking content-type and size is to request a pre signed url to upload the file. A JWT signature is going to be required in order to confirm that who signed the request and upload the file to the temporary staging area is in possession of authorized keys with write permissions in NxtFi API
Generate a SHA-256 Hash from the file.
Build the JWT signature using the JOSE library as described below:
Files reaching staging area will have a life-cycle until complete deletion of 24hrs. Avoid changing the setExpirationTime()
property to prevent uncaught exceptions.
/newfile
endpoint.After receiving the success response from the PUT call to /newfile, the content can be uploaded to the provided URL using the response fields as template call fields. In this context, we will describe the implementation of the POST method using the FormData browser API.
Once a file is successfully uploaded, it will be temporarily stored in a staging folder while waiting for persistence. This staging folder serves as an intermediate storage location before the file is permanently stored. However, files in the staging folder have a maximum duration of 24 hours.
To ensure the file's long-term persistence, a block must be signed by the same entity who uploaded the file. By propagating a blockchain-confirmed block, its storage and availability are guaranteed.
If the file is not persisted within the 24-hour timeframe, it will be permanently deleted from the staging folder. This mechanism ensures that only files persisted in blocks are permanently stored.
Use the custom function persistArchive
to ensure file long-term and proper path generation. A optional data
field is available to add custom metadata to the file block registration
Treated as every stored value in the NxtFi storage system, the file can be required through a get function
at contract level:
or as an endpoint query call:
Note: When querying the result value, neither at contract level or at endpoint call the extension of the file is provided.
and the response object will be like this below. Will include the Url were the file is located and can be downloaded.