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

dpd-fileupload

v0.0.17

Published

File uploader for Deployd

Downloads

45

Readme

File uploader Module for Deployd

npm David Build Status

Check out this repo for a demo of this module.

Description

This module provides functionality to upload files within Deployd. The uploaded files will be stored in the public folder of Deployd and the filenames will be stored in a collection.

Don't hesitate to fill an issue if you find a bug or need a feature.

Installation

Go to the base directory of your Deployd project and enter:

$ npm install deployd
$ npm install dpd-fileupload --save

Once installed, you can add a resource of type fileupload in the dashboard. Installaton

Development

$ git clone [email protected]:NicolasRitouet/dpd-fileupload.git
$ cd dpd-fileupload
$ npm install deployd
$ npm link

Configuration

By default, the module will create a folder called "upload" inside the public directory. You can then access your files by calling: http://localhost:2403/upload/filename.extension Directory structure

If you need to, you can change the name of the directory in the dashboard under CONFIG. Configuration

Usage

Upload a file (or multiple files)

Method POST or PUT (set content type to "multipart/form-data"), send "subdir" as request param to save the file in a sub directory. Any request parameter sent will be stored in the resource object.

Working demo available here: https://github.com/NicolasRitouet/dpd-fileupload-demo

Response of a successful upload:

[{
	filename: 'screenshot.png',
    subdir: "images",
    creationDate: 1389946339569,
    id: '2f4c752310e2bbae',
    filesize: '75148412',
    optionalParam:'foobar'
}, {
	filename: 'screenshot (1).png',
    subdir: "images",
    creationDate: 1389946339233,
    id: 'ef43f52310e2bbae',
    filesize: '85412',
    optionalParam:'foobar'
}, ...]

Get the list of files

Method GET

dpd.fileupload.get(function(result, err) {
    console.log(result);
});

The response:

[{
	filename: 'screenshot.png',
    subdir: "images",
    creationDate: 1389946339569,
    id: '2f4c752310e2bbae',
    filesize: '75148412',
    optionalParam:'foobar'
}, {
	filename: 'screenshot (1).png',
    subdir: "images",
    creationDate: 1389946339233,
    id: 'ef43f52310e2bbae',
    filesize: '8441547',
    optionalParam:'foobar'
}, ...]

Get one file

Since we upload the files into the /public folder, you can access your files like this: http://localhost:2403/upload/subdir/filename.extension replace:

  • "upload" by the folder your set in the dashboard
  • "subdir" by the value you set for subdir. (nothing if you haven't given a subdir param)
  • "filename.extension" by the name of the file your uploaded

If you would like more security and some rights management to get the files, fill an issue about this and I might work on this feature.

Remove a file from filesystem and from collection

Method DELETE

    dpd.fileupload.del(id, function(result, err) {
        if (err) alert(err);
        console.log(result);
    });

events

This module provides three custom events in the dashboard: get, upload, delete
They contains the following variables:

  • ctx: more documentation on [docs.deployd.com](http://docs.deployd.com/docs/collections/reference/event-api.html#s-ctx -764)
  • the upload event also contains the following objects:
    • url
    • filename
    • originalFilename
    • filesize
    • uniqueFilename
    • subdir

Example on dpd-fileupload-demo

authentication

Thanks to @Mortgy, we now have authentication within dpd-fileupload.
There's a new checkbox in the dashboard to configure the authorization. If you need your users to be logged-in to view, upload or delete the files, this checkbox is yours! If your users are logged-in with deployd, they'll have access to the resources.

Changelog

  • 0.0.17
    • Implemented user authentication configuration to allow file uploading / deleting for loggedin users PR #43 (Thanks @Mortgy)
    • unique filename enabling could be configured in configuration PR #43 (Thanks @Mortgy)
  • 0.0.16
  • 0.0.15
    • Add data in upload event.
    • Partial fix of E11000 error PR #36 (Thanks @hjanuschka). The rest of the fix is on Deployd side (#653)
    • Switch to new md5 dependency (MD5 was deprecated). PR #31
    • We now have integration tests, maintainance will be much easier :sunglasses:
  • 0.0.14
  • 0.0.13
    • Fixed bug for deleting without a subdirectory. PR #22 (thanks @rgolea)
    • Upgrade dependency (debug module).
  • 0.0.12
    • fix: public folder not dynamic. PR #19 (thanks @docnoe)
    • Update dependencies. Close #17
    • rename mimeType property to type to match the html5 file spec. Close #14
  • 0.0.11
    • Allow internal requests for GET. Close #12
    • Added MIME types and filtering file lists. PR #5
  • 0.0.10
    • Option to store unique file name (add uniqueFilename to the query param. Cf Demo)
      • npm update required (MD5 dependency added)
    • if the name of the resource is the same of the upload directory, it'll automatically append an underscore (_) to the upload directory (cf demo)
  • 0.0.9
    • Store file size
  • 0.0.8
    • any parameter send in the query will be stored in the resource (and its value will be parsed as JSON if applicable)
    • if a parameter property name is "subdir", file will be placed under this subdir in the upload directory
  • 0.0.7
    • fix empty response issue
  • 0.0.6
  • 0.0.5

Todo

  • send an event with progress of upload=
  • improve demo (add implementation with angularJS, send a param in the query)
  • check if file already exist (upload anyway and put a (1) in the filename or return an error?)
  • Find a cleaner way to get the path of the upload directory
  • Implement GET of one file (stream file ?)