JSPM

opex-telegraph-uploader

2.1.1
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • Downloads 7
    • Score
      100M100P100Q55550F
    • License ISC

    A package that helps you to upload media files to telegra.ph

    Package Exports

    • opex-telegraph-uploader

    Readme

    opex-telegraph-uploader

    A module for uploading images to the Telegraph service.

    Installation

    npm install opex-telegraph-uploader

    ES6

    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: 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.

      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: An object with information about the uploaded image (see upload).

        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: An object with information about the uploaded image (see upload).

          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: