Skip to main content

Create Media

uploadMedia

For creating a new media you need to use uploadMedia and provide a File/Blob, its MIME type, and a file name. Allowed file types are: jpeg, gif, png, jpg, pdf.

On web, the file must be a real File/Blob object (e.g. taken from an <input type="file"> element or DataTransfer), not a path string.

Parameters

  • file: (File | Blob) - The file to upload.
  • type: (string) - The MIME type of the file.
  • fileName: (string) - The name of the file.

Returns

  • Promise<ResponseType<MediaType>>: A promise that resolves with a MediaType object containing the uploaded media data.

Example

import React from 'react';
import { uploadMedia } from 'react-web-altibbi';

function FileUploader() {
const onFileSelected = (event: React.ChangeEvent<HTMLInputElement>) => {
const file = event.target.files?.[0];
if (!file) return;

uploadMedia(file, file.type, file.name).then((res) => {
console.log(`Media ID: ${res?.data?.id}`);
});
};

return <input type="file" accept="image/*,application/pdf" onChange={onFileSelected} />;
}

Responses

Status 200

Success

{
"id": "1234123",
"type": "image",
"name": "Test file",
"path": "doc/2024/02/05/60037901f47939872a6e1bdb9a65f604.png",
"extension": "png",
"size": 362875,
"url": "https://altibbi.com/Medias/12123/2331.png"
}

Status 401

UnauthorizedHttpException represents an Unauthorized HTTP exception with status code 401.

{
"name": "Unauthorized",
"message": "Your request was made with invalid credentials",
"code": "0",
"status": "401",
"type": "yii\\web\\UnauthorizedHttpException"
}

Status 422

Data Validation Failed.

[
{
"field": "string",
"message": "string"
}
]