1.1.0 • Published 1 year ago

mushroomjs-file v1.1.0

Weekly downloads
1
License
ISC
Repository
-
Last release
1 year ago

Install

npm install mushroomjs-file

Or

yarn add mushroomjs-file

Dependent on

mushroomjs

Import

import mushroom from "mushroomjs-file";

Or

import mushroom from "mushroomjs";
import "mushroomjs-file";

Usage

Upload file

// upload binary file
let result = await mushroom.$file.uploadAsync({
    file: document.getElementById("fileUpload").files[0], // required
    name: "Name of file with extension", // optional
    tags: [ "tag1", "tag2" ], // optional
    contentFormat: "BINARY", // optional, default: BINARY
    progress: () => { /* Handle progress event */} // optional
});

// upload BASE64 file
let result = await mushroom.$file.uploadAsync({
    file: document.getElementById("txtBase64").value, // required
    name: "Name of file with extension", // required
    tags: [ "tag1", "tag2" ], // optional
    contentFormat: "BASE64", // required
    progress: () => { /* Handle progress event */} // optional
});

// upload a FormData
let formData = new FormData();
formData.append("file", value, "Name of file with extension"); // value can be a String or Blob
let result = await mushroom.$file.uploadAsync({
    file: formData, // required
    name: "Name of file with extension", // required
    tags: [ "tag1", "tag2" ], // optional
    contentFormat: "FORMDATA", // required
    progress: () => { /* Handle progress event */} // optional
});

Download file

Support in web browser only

// download single file
mushroom.$file.download(fileId);

// download multiple files
mushroom.$file.zip([fileId1, fileId2]);

Make file link

let fileLink = mushroom.$file.linkBuilder.download.id(fileId).build();
let zipLink = mushroom.$file.linkBuilder.zip.add(fileId1).add([fileId2, fileId3]).build();

// or shortcut
let fileLink = mushroom.$file.getDownloadLink(fileId);
let zipLink = mushroom.$file.getZipLink([fileId1, fileId2, fileId3]);

Make image thumbnail link

let imgSrc = mushroom.$file.linkBuilder.thumb
    .id(fileId) // required
    // .stretch(width: number, height: number)
    // .square(size: number)
    // .zoom(width: number, height: number, backgroundColor?) // backgroundColor: optional, default: transparent, valid values: transparent | [0-9a-fA-F]{6}
    // .x(width: number)
    // .y(height: number)
    .clip(150, 75, ImageVerticalAlign.TOP, ImageHorizontalAlign.LEFT) 
    // .clip(width: number, height: number, va?: ImageVerticalAlign, ha?: ImageHorizontalAlign)
    // .addEffect(effect)
    .rotate90()
    // .rotate180()
    // .rotate270()
    .flipVertical()
    .transparent(50) // value: from 0 to 255
    .grayscale()
    .format(ImageOutputFormat.PNG) // ImageOutputFormat: SOURCE, JPG, PNG, GIF, WEBP, AUTO
    .build();

Release notes

1.1.0

New features:

  • Support TypeScript
  • Compatible with mushroomjs@1.1.*
1.1.0

1 year ago

1.1.0-alpha.4

2 years ago

1.1.0-alpha.2

2 years ago

1.1.0-alpha.3

2 years ago

1.1.0-alpha.1

3 years ago

1.0.0

4 years ago