mushroomjs-file
v1.2.0
Published
Extension File for mushroomjs
Downloads
47
Readme
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]);
Inline mode
let fileLink = mushroom.$file.linkBuilder.download.id(fileId).inline().build();
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()
// .flipHorizontal()
.transparent(50) // value: from 0 to 255
.grayscale()
.allowSmallerSize()
// .allowSmallerSize(allow: boolean)
.format(ImageOutputFormat.PNG) // ImageOutputFormat: SOURCE, JPG, PNG, GIF, WEBP, AUTO
.build();
Release notes
1.2.0
New features:
- Support
inline
download - Support
allowSmallerSize
thumb - Compatible with
[email protected]
1.1.0
New features:
- Support TypeScript
- Compatible with
[email protected].*