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

store-file

v1.0.3

Published

**with this package you can upload file from either formdata, or dataUrl or buffer. you can also parse formdata fields and files with this pakage.**

Downloads

6

Readme

About this package

with this package you can upload file from either formdata, or dataUrl or buffer. you can also parse formdata fields and files with this pakage.

these three awesome following packages are used in this package

uuid busboy file-type

Get started

npm i store-file --save

Examples

we use express server for examples.

    const { uploadFile, setOptions } = require('store-file');

	setOptions([{ fieldName: 'filetoupload', filePath: '/public',fileName: 'name'}]);
	//or
	setOptions([{ fieldName: 'filetoupload', filePath: '/public'}]);
	// in this case name would be a random and unique string like 86c62f37-05fb-4662-bcdf-1c1603f49ce9
	// uuid package is used for names
        app.post('/upload', uploadFile, (req, res) => {
		console.log(req.body);// including form data fields
		//result of req.body
		// {foo:'bar'}		
		console.log(req.files);// array of uploaded files
		//result of req.files
		//[{
		//     fieldName: 'a',
		//     fileName: '86c62f37-05fb-4662-bcdf-1c1603f49ce9',
		//     filePath: '/public',
		//     originalName: 'iSSTP_v1.3_20161009.zip',
		//     encoding: '7bit',
		//     mimeType: 'application/zip',
		//     buffer: <Buffer 50 4b 03 04 0a 00 00 00 00 00 88 bd 44 49 00 00 00 00 00 00 00 00 00 00 00 00 0a 00 10 00 69 53 73 74 70 2e 61 70 70 2f 55 58 0c 00 13 c4 f9 57 3f c0 ... 4417684 more bytes>
		//}]

		res.end();
	});

and on front end

	const [file] = document.querySelector('.file').files;
	const  formData = new  FormData();
	formData.append('filetoupload', file);
	formData.append('foo', 'bar');
	$.ajax({
		url:  `/upload`,
		type:  'POST',
		data:  formData,
		cache:  false,
		enctype:  'multipart/form-data',
		contentType:  false,
		processData:  false,
	}).done(data  => {
		console.log(data);
	});

or you can also parse form data and store the file

	const { parsFormData, uploadFromBuffer, uploadFromDataUrl } = require('store-file');
	app.post('/upload', parsFormData, async (req, res) => {
		console.log(req.files);
		//[{
		//	fieldName:  'a',
		//	originalName:  'something.zip',
		//	encoding:  '7bit',
		//	mimeType:  'application/zip',
		//	buffer:  <Buffer  50  4b  03  04  0a  00  00  00  00  00  88  bd  44  49  00  00  00  00  00  00  00  00  00  00  00  00  0a  00  10  00  69  53  73  74  70  2e  61  70  70  2f  55  58  0c  00  13  c4  f9  57  3f  c0  ...  4417684  more  bytes>
		//}]
		const { buffer } = req.files[0]
		const { filePath } = await uploadFromBuffer({ buffer , fileName: 'name', filePath: '/public' });
		//{ filePath: '/public/b243610d-ba38-474b-aa51-45f6ac3d07da.zip' }

		//or you can also store dataUrl

		const { filePath } = await uploadFromDataUrl({ dataUrl:data_url , fileName: 'name', filePath: '/public' });
		
	
	});