A module for uploading images to the Telegraph service.
npm install opex-telegraph-uploader
import { upload, uploadByUrl, uploadByBuffer, uploadByPath } from 'opex-telegraph-uploader';
const { upload, uploadByUrl, uploadByBuffer, uploadByPath } = require('opex-telegraph-uploader');
Note:
- Supported image formats: JPEG (.jpg, .jpeg) and PNG (.png).
A universal function for uploading images. It automatically determines the input type and uses the appropriate upload method.
-
input
(string | Buffer): Image URL, file path, or Buffer with image data. -
agent
(optional): HTTP/HTTPS agent for making the request.
- Promise: An object with information about the uploaded image.
-
link
(string): Full URL of the uploaded image. -
path
(string): Path to the image on the Telegraph server.
-
// Upload by URL
const result1 = await upload('https://example.com/image.jpg');
console.log(result1.link);
// Upload local file
const result2 = await upload('/path/to/local/image.png');
console.log(result2.link);
// Upload from Buffer
const buffer = Buffer.from('...'); // image data
const result3 = await upload(buffer);
console.log(result3.link);
Uploads an image from the specified URL.
-
url
(string): URL of the image to upload. -
agent
(optional): HTTP/HTTPS agent for making the request.
- Promise: An object with information about the uploaded image (see
upload
).
const result = await uploadByUrl('https://example.com/image.jpg');
console.log(result.link);
Uploads an image from a Buffer.
-
buffer
(Buffer): Buffer containing the image data. -
contentType
(string): MIME type of the image (e.g., 'image/jpeg', 'image/png'). -
agent
(optional): HTTP/HTTPS agent for making the request.
- Promise: An object with information about the uploaded image (see
upload
).
const buffer = await fs.readFile('image.jpg');
const result = await uploadByBuffer(buffer, 'image/jpeg');
console.log(result.link);
Uploads an image from a local file.
-
filePath
(string): Path to the local image file. -
agent
(optional): HTTP/HTTPS agent for making the request.
- Promise: An object with information about the uploaded image (see
upload
).
const result = await uploadByPath('/path/to/image.png');
console.log(result.link);
Developer: OpexDev