API Temporary Image Link
Upload ảnh tạm thời & tạo link
Mục lục
Tổng quan
API này cho phép upload ảnh và tạo link tạm thời cho user. Có đầy đủ kiểm tra quota, trùng lặp và phân quyền access type.
Endpoint
POST
https://technt.net/api/v1/temp-img-link/quick-upload
Request
Headers
Tên | Giá trị |
---|---|
Authorization | Bearer {api_token}
|
Content-Type | application/json |
Response
201 Created
Thành công
{
"success": true,
"message": "Upload & tạo link thành công!",
"data": {
"image_id": 1,
"original_name": "abc.jpg",
"link_url": "https://technt.net/i/raw/xxxx",
"expires_at": "2025-06-07T10:00:00Z",
"access_type": "public"
}
}
409 Conflict
Trùng ảnh
{
"success": false,
"message": "Bạn đã upload ảnh này trước đó!"
}
403 Forbidden
Vượt quota
{
"success": false,
"message": "Bạn đã vượt quá quota upload ảnh!"
}
Ví dụ sử dụng
// Ví dụ: upload ảnh bằng fetch, tự động encode base64 từ file input
const fileInput = document.querySelector('#file');
const token = 'Bearer ...'; // điền token của bạn
const uid = '...'; // điền UID của bạn
const accessType = 'public'; // public hoặc private
fileInput.addEventListener('change', function() {
const file = fileInput.files[0];
const reader = new FileReader();
reader.onload = function(e) {
const base64 = e.target.result.split(',')[1];
fetch('https://technt.net/api/v1/temp-img-link/quick-upload', {
method: 'POST',
headers: {
'Authorization': token,
'Content-Type': 'application/json',
'Accept': 'application/json'
},
body: JSON.stringify({
image_base64: base64,
access_type: accessType,
uid: uid
})
})
.then(res => res.json())
.then(console.log);
};
reader.readAsDataURL(file);
});
Lưu ý: Tham số
Nếu không truyền hoặc truyền sai, API sẽ trả về lỗi
Lấy UID của bạn tại Quản lý API.
uid
là bắt buộc và phải
trùng với user của token.Nếu không truyền hoặc truyền sai, API sẽ trả về lỗi
403 Forbidden
.Lấy UID của bạn tại Quản lý API.