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

adias-file-uploader

v3.0.6

Published

Angular Library for uploading files

Downloads

13

Readme

adias-file-uploader

npm version


File Uploader for Angular

  • [x] Currently Support single file upload
  • [x] Set Custom File Url After Upload
  • [x] Transparent Uploader
  • [x] Multiple File Uploader

see Demo here

Example:

app.module.ts

import { FileUploaderModule } from "adias-file-uploader";

FileUploaderModule.forRoot({
  endPoint: "https://api.example.com/api/upload"
});

OR

FileUploaderModule.forRoot({
  endPoint: "/upload"
});

app.component.html

<div ngxFilePicker (uploadSuccess)="onUploadSuccess($event)"></div>

OR


Custom file url can be also used

<div ngxFilePicker [fileUrl]="uploadedFileUrl" (uploadSuccess)="onUploadSuccess($event)"></div>

OR

For Transparent File uploader

<div ngxFilePicker transparent (uploadSuccess)="onUploadSuccess($event)"></div>

OR

For Multiple File upload

<div ngxFilePicker transparent multiple (uploadMultiSuccess)="onUploadSuccess($event)" (uploadFailed)="onUploadFail($event)"></div>

Events

  • uploadSuccess (Output):

_function launched after picture successfully uploaded.

The value returned in $event.

app.component.ts

 onUploadSuccess(e:  FilePickerRespnse) {
  console.log("fileUrl ===", e.fileUrl);
  console.log("fileName ===", e.fileName);
  console.log("fileSize ===", e.fileSize);
 }

Nestjs

controller.ts



  @Post()
  @AllowWithoutToken()
  @UseInterceptors(FilesInterceptor('files'))
  async uploadAvatar(@UploadedFiles() files: S3Response[]) {
    return files.map(file => {
      return {
        fileUrl: buildFileUrl(file.key),
        fileName: file.key,
        fileSize: file.size,
        fileType: file.mimetype,
      };
    });
  }

s3.service.ts

import { Injectable, Logger } from "@nestjs/common";
import {
  MulterModuleOptions,
  MulterOptionsFactory
} from "@nestjs/platform-express";
import * as AWS from "aws-sdk";
import * as Express from "express";
import * as Multer from "multer";
import * as MulterS3 from "multer-s3";
import { Random } from "random-js";

const random = new Random();
@Injectable()
export class S3Service implements MulterOptionsFactory {
  private s3: any;
  private readonly FILE_LIMIT_SIZE = 3145728; // 사용자 프로필 이미지는 3MB 제한
  config = {
    acesssKeyId: acesssKeyId,
    bucket: bucket,
    secretAccessKey: secretAccessKey
  };
  constructor() {
    this.s3 = new AWS.S3();

    AWS.config.update({
      accessKeyId: acesssKeyId,
      secretAccessKey: secretAccessKey
    });
  }

  // CallBack 함수로, NestJS의 MulterModule에 사용될 MulterModuleOption을 리턴한다.
  createMulterOptions(): MulterModuleOptions | Promise<MulterModuleOptions> {
    const bucket: string = this.config.bucket;
    const acl: string = "public-read";

    const multerS3Storage = MulterS3({
      s3: this.s3,
      bucket,
      //   acl,
      metadata: (req, file, cb) => {
        cb(null, { fieldName: file.fieldname });
      },
      key: (req, file, cb) => {
        cb(
          null,
          `${Date.now().toString()}-${String(file.originalname).replace(
            /[&\/\\#, +()$~%'":*?<>{}]/g,
            "_"
          )}`
        );
      }
    });

    return {
      storage: multerS3Storage,
      fileFilter: this.fileFilter,
      limits: {
        fileSize: this.FILE_LIMIT_SIZE
      }
    };
  }

  public fileFilter(
    req: Express.Request,
    file: Multer.File,
    cb: (error: Error | null, acceptFile: boolean) => void
  ) {
    if (file.mimetype.match(/\/(jpg|jpeg|png|gif)$/)) {
      cb(null, true);
    } else {
      Logger.log(`No! ${JSON.stringify(file)}`);
      cb(new Error("unsupported file"), false);
    }
  }
}