GithubHelp home page GithubHelp logo

devfelipereis / ion-media-cache Goto Github PK

View Code? Open in Web Editor NEW

This project forked from leo1305pineda/ion-media-cache

0.0 1.0 0.0 26 KB

Use this directive to save image in device ios or android.

JavaScript 2.91% TypeScript 97.09%

ion-media-cache's Introduction

Ion Media Cache

Directive cache multimedia.

Usage notice

With this directive you can download file to the device using Fetch API and render the source in the component. If your application is PWA, it use FileSystem to save the blob.

Supported Platforms.

* Android
* Browser
* Ios

Installation

npm i ion-media-cache@latest.

require installation ionic native

File

Quickstart

Import ion-media-cache in you module page.

// Import the module
import { IonMediaCacheModule } from 'ion-media-cache';
...
@NgModule({
    (...)
    imports: [
        IonMediaCacheModule
    ],
    (...)
})
export class PageModule {}

Usage

image

<img [url]="image" [customCache]="{fallbackUrl: '/assets/img/default.png'}" alt="ion-media-cache" />

<ion-img [url]="image" [customCache]="{fallbackUrl: '/assets/img/default.png'}"></ion-img>

custom div background

<div
    [url]="image"
    [customCache]="{fallbackUrl: '/assets/img/default.png', render: 'background', spinner: false, fallbackReload: false}"
    style="background-repeat: no-repeat;background-position: center;background-size: cover;width: 100%;height: 100%;"></div>

audio

<audio controls name="media">
  <source [url]="audio" customCache>
</audio>

Events

<ion-img
    #elRef
    [url]="image"
    [customCache]="{ fallbackUrl: '/assets/img/bienvenida.png', cache_expire: {time: n.component?.expire_subimage, data: data } }"
    (onExpireCache)="onExpireCache($event, elRef)"
    (ionImgDidLoad)="ionImgDidLoad($event)"
    (ionError)="ionError($event)"
></ion-img>
onExpireCache(event) {
    console.log(event);
    event.el.clearImageCache(event.data.url);
}
ionImgDidLoad(event) {
    console.log(event);
}
ionError(event) {
    console.log(event);
}

Optional custom cache

customCache = {
    debugMode: false,                       // boolean default = false;
    enabled: true,                          // booleandefault = true;
    corsFromHeroku: false                    // fix https://stackoverflow.com/a/21136980/7638125
    fallbackUrl: '',                        // string usage uri fail 'assetes/img/default.png'.
    concurrency: 5,                         // number default = 5, only on android, ios.
    maxCacheSize: -1,                       // number default -1, without limit.
    maxCacheAge: -1,                        // number default -1, without limit.
    httpHeaders: ,                          // any default = {}.
    fileNameCachedWithExtension: true,      // boolean default = true, save file with extension.
    fallbackFileNameCachedExtension: '.jpg',// string default '.jpg', extension to save.
    cacheDirectoryType: 'external',         // 'cache' | 'data' | 'external' default = 'external'.
    imageReturnType: 'uri',                 // 'base64' | 'uri' default = 'uri'.
    cacheDirectoryName: 'ion-media-cache',  // string default = 'ion-media-cache'.
    cache_expire: undefined,                // any default undefined, usage { time: new Date().getTime() + (1000 * [unit_second]) }.
    cache = true,                           // boolean defaul = true, activeted cache.
    render: 'src',                          // string default, render to property src.
    spinner: `
    <ion-spinner name="crescent">
    </ion-spinner>`,                        // any usage innertHtml. or false to disabled spinner
    fallbackReload: `
    <ion-icon name="cloud-offline" style="font-size: 2.7em;"></ion-icon>
    `,                                      // any;usage innertHtml. or false to disable fallbackReload

}

IonMediaCache

// Print current cache loader in the DOM
// Use console inspect in the browser
IonMediaCache

Testing fetch

fetch('http://cors-anywhere.herokuapp.com/https://lorempixel.com/640/480/?60789', {
   headers: {},
}).then((response) => {
   return response.blob();
}).then((blob) => {
   console.log(blob);
}).catch((e) => console.log(e));

Cors Erros Configuring Cors For Laravel Public Storage

fix stackoverflow

customCache = {
    corsFromHeroku: true // this is default false, limited use fix https://stackoverflow.com/a/21136980/7638125
}

CORS Anywhere is a NodeJS proxy which adds CORS headers to the proxied request.

If you expect lots of traffic, please host your own instance of CORS Anywhere, and make sure that the CORS Anywhere server only whitelists your site to prevent others from using your instance of CORS Anywhere as an open proxy.

Demo Server CORS Anywhere

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.