npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mediacloud-server-client

v1.0.7

Published

A TypeScript package for uploading files to Media Cloud API

Downloads

41

Readme

Media Cloud Uploader

A TypeScript package for uploading single or multiple files to the Media Cloud API, fetching uploaded media, soft delete and permanent delete.

Supported Formats

  • jpeg
  • png
  • jpg
  • gif
  • svg
  • mp4
  • mp3
  • pdf
  • doc
  • docx
  • xls
  • xlsx
  • ppt

Installation

npm install mediacloud-server-client

Usage

import { MediaCloudUploader } from 'mediacloud-server-client';

async function main() {
  const uploader = new MediaCloudUploader('your-api-key');

  try {
    // Upload a single file
    const imageUrl = await uploader.uploadFile({
      filePath: '/path/to/your/file1.jpg',
      optimize: true //optional and it only works for image files, other file type will not be optimized
    });
    console.log('Uploaded image URL:', imageUrl);

    // Upload multiple files
    const multipleImageUrls = await uploader.uploadMultipleFiles({
      filePaths: ['/path/to/your/file1.jpg', '/path/to/your/file2.png', '/path/to/your/file3.gif'],
      optimize: true //optional and it will only optmized image files, other file type will not be optimized
    });
    console.log('Uploaded image URLs:', multipleImageUrls);

    // Fetch uploaded media
    const page = 1
    const uploadedMedia = await uploader.getMedias(page);
    console.log('Uploaded media:', uploadedMedia);

    // Move item to trash
    const mediaId = 'bWVkaWEvaW1hZ2VzL29yaWdpbmFsL3JqMExYTUlPOUtLSDc2UXRwZkRIeEJ6NGwzN1VIb01aVWdUbnR0cVcucG5n';
    await uploader.softDeleteMedia(mediaIdToDelete);
    console.log('Media deleted successfully');

    // Delete a media item
    const mediaIdToDelete = 'bWVkaWEvaW1hZ2VzL29yaWdpbmFsL3JqMExYTUlPOUtLSDc2UXRwZkRIeEJ6NGwzN1VIb01aVWdUbnR0cVcucG5n';
    await uploader.deleteMedia(mediaIdToDelete);
    console.log('Media deleted successfully');
    
  } catch (error) {
    console.error('Operation failed:', error);
  }
}

main();

API

MediaCloudUploader

A class that handles file uploads to the Media Cloud API, fetches uploaded media, and deletes media.

Running Tests

To run the tests for this package, make sure you have Jest installed:

npm test

Constructor

new MediaCloudUploader(apiKey: string)
  • apiKey (string): Your Media Cloud API key.

Methods

uploadFile(options: UploadOptions): Promise<string>

Uploads a single file to the Media Cloud API.

Options
  • filePath (string): The path to the file you want to upload.
  • optimize (boolean, optional): Whether to optimize the uploaded media. Defaults to true.
Returns

A promise that resolves to the URL of the uploaded media.

uploadMultipleFiles(options: MultipleUploadOptions): Promise<string[]>

Uploads multiple files to the Media Cloud API.

Options
  • filePaths (string[]): An array of file paths to upload.
  • optimize (boolean, optional): Whether to optimize the uploaded media. Defaults to true.
Returns

A promise that resolves to an array of URLs of the uploaded media.

getMedias(page?: number): Promise<PaginatedMediaResponse>

Fetches the list of uploaded media from the Media Cloud API.

Parameters
  • page (number, optional): The page number of results to fetch. Defaults to 1.
Returns

A promise that resolves to a PaginatedMediaResponse object containing the list of media URLs and pagination information.

deleteMedia(mediaId: string): Promise<void>

Deletes a specific media item from the Media Cloud API.

Parameters
  • mediaId (string): The ID of the media item to delete. This is the last part of the media URL after /media/.
Returns

A promise that resolves when the media item is successfully deleted.

Types

MediaItem

A string representing the URL of an uploaded media item.

PaginatedMediaResponse

An object containing the paginated list of media items and related pagination information.

License

MIT