May 18, 2024
Using MediaLit in your app is as easy as consuming any REST endpoint. You do not have to install anything.
You need to create an app and obtain an API key to upload the file.
Read how to do that in 2 minutes here.
To upload a file, simply send an HTTP request to the following REST endpoint along with the required data.
POST http://api.medialit.cloud/media/create
Add the form data to your request, containing the following properties.
apikey (type: string
) (required): To authenticate your request.
file (type: file
) (required): The actual file.
access (type: true
|false
) (optional): If the file is open to everyone or not. If you do not specify this property, the uploaded file will be private i.e. requires authorization to access it.
caption (type: string
) (optional): A caption for the file
group (type: string
) (optional): A discreet string you would like to attach to the file. This comes handy for grouping files on your application side.
If the request goes through, you will get a response like the following.
{
"mediaId": "iEZYLi_hy",
"originalFileName": "some-file.png",
"mimeType": "image/png",
"size": 10240,
"access": "private",
"file": "https://d27g932tzd9f7s.cloudfront.net/medialit-service/public/b-H8rrVnm3t5fTQy9OJ9T7iq3X6UKCD2xmjXwuio/main.png",
"thumbnail": "https://d27g932tzd9f7s.cloudfront.net/medialit-service/public/b-H8rrVnm3t5fTQy9OJ9T7iq3X6UKCD2xmjXwuio/thumb.webp"
}
There are a few details you would like to understand about the returned response.
mediaId: Every uploaded file on MediaLit gets a unique id which uniquely identifies the file on the service. You will use this id to perform actions on the file.
access: If the file is open to everyone.
size: Total file size in bytes.
file: The direct URL to the file.
In case of public files i.e. (the access is
public
), this can be re-used. However, in case of private files (the access inprivate
) this URL needs to be generated everytime you want to show/access the file.
thumbnail: A direct URL to the generated thumbnail for the file. This will always be public and can you saved by your app.
MediaLit does not allow updating details of the uploaded file later. It is to keep the objects immutable so that the things don't start breaking in your apps if you update a file.
MediaLit offers an alternate way to generate a unique one-time upload URL which you can hand over the client (or your frontend) and they can upload data directly to MediaLit, without any intermediate server.
You can use this mechanism to generate the unique upload links on the server side, where you have access to the API key.
To obtain the unique one-time upload link, send an HTTP request to the following endpoint.
POST http://api.medialit.cloud/media/presigned/create
Content-Type: application/json
{
"apikey": "your API key"
}
If the request goes through, you will get a response like the following.
{
"message": "https://api.medialit.cloud/media/create?signature=I7Mr5htp5sN6s43PfXeEaFVMR1Pc"
}
Your client (or the frontend app) can use this URL to upload a file. It accepts all parameters supported by the previous /media/create
endpoint, except apikey
.
You can access any file by using its mediaId
.
To obtain the file's details, send an HTTP request to the following endpoint. Just replace the <media-id>
with the actual media id.
POST https://api.medialit.cloud/media/get/<media-id>
Content-Type: application/json
{
"apikey": "your API key"
}
If the request goes through, you will get a response like the following.
{
"mediaId": "iEZYLi_hy",
"originalFileName": "some-file.png",
"mimeType": "image/png",
"size": 10240,
"access": "private",
"file": "https://d27g932tzd9f7s.cloudfront.net/medialit-service/public/b-H8rrVnm3t5fTQy9OJ9T7iq3X6UKCD2xmjXwuio/main.png",
"thumbnail": "https://d27g932tzd9f7s.cloudfront.net/medialit-service/public/b-H8rrVnm3t5fTQy9OJ9T7iq3X6UKCD2xmjXwuio/thumb.webp"
}
You can access a paginated list of all of your files.
To get this, send an HTTP request to the following endpoint.
POST https://api.medialit.cloud/media/get
Content-Type: application/json
{
"apikey": "your API key"
}
If the request goes through, you will get a response like the following.
[
{
"mediaId": "iEZYLi_hy",
"originalFileName": "some-file.png",
"mimeType": "image/png",
"size": 10240,
"access": "private",
"file": "https://d27g932tzd9f7s.cloudfront.net/medialit-service/public/b-H8rrVnm3t5fTQy9OJ9T7iq3X6UKCD2xmjXwuio/main.png",
"thumbnail": "https://d27g932tzd9f7s.cloudfront.net/medialit-service/public/b-H8rrVnm3t5fTQy9OJ9T7iq3X6UKCD2xmjXwuio/thumb.webp"
},
{
"mediaId": "iEZYLi_hy2",
"originalFileName": "some-file2.png",
"mimeType": "image/png",
"size": 10240,
"access": "private",
"file": "https://d27g932tzd9f7s.cloudfront.net/medialit-service/public/b-H8rrVnm3t5fTQy9OJ9T7iq3X6UKCD2xmjXwuio/main.png",
"thumbnail": "https://d27g932tzd9f7s.cloudfront.net/medialit-service/public/b-H8rrVnm3t5fTQy9OJ9T7iq3X6UKCD2xmjXwuio/thumb.webp"
}
]
To delete a file, send an HTTP request to the following endpoint. Just replace the <media-id>
with the actual media id.
DELETE https://api.medialit.cloud/media/delete/<media-id>
Content-Type: application/json
{
"apikey": "your API key"
}
If the request goes through, you will get the following response.
{
"message": "success"
}
That's it! It is that easy.
Feel free to reach out to us, using the chatbot provided here or through our Discord. We are happy to help you out.