Package Exports
- opex-telegraph-uploader
Readme
opex-telegraph-uploader
A module for uploading images to the Telegraph service.
Installation
npm install opex-telegraph-uploaderES6
import { upload, uploadByUrl, uploadByBuffer, uploadByPath } from 'opex-telegraph-uploader';CommonJS
const { upload, uploadByUrl, uploadByBuffer, uploadByPath } = require('opex-telegraph-uploader');Note:
- Supported image formats: JPEG (.jpg, .jpeg) and PNG (.png).
API
upload(input[, agent])
A universal function for uploading images. It automatically determines the input type and uses the appropriate upload method.
Parameters:
input(string | Buffer): Image URL, file path, or Buffer with image data.agent(optional): HTTP/HTTPS agent for making the request.
Returns:
- Promise
Examples:
// 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);uploadByUrl(url[, agent])
Uploads an image from the specified URL.
Parameters:
url(string): URL of the image to upload.agent(optional): HTTP/HTTPS agent for making the request.
Returns:
- Promise
Example:
const result = await uploadByUrl('https://example.com/image.jpg');
console.log(result.link);uploadByBuffer(buffer, contentType[, agent])
Uploads an image from a Buffer.
Parameters:
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.
Returns:
- Promise
Example:
const buffer = await fs.readFile('image.jpg');
const result = await uploadByBuffer(buffer, 'image/jpeg');
console.log(result.link);uploadByPath(filePath[, agent])
Uploads an image from a local file.
Parameters:
filePath(string): Path to the local image file.agent(optional): HTTP/HTTPS agent for making the request.
Returns:
- Promise
Example:
const result = await uploadByPath('/path/to/image.png');
console.log(result.link);Developer: OpexDev