Giter Club home page Giter Club logo

server-uploader's Introduction

Readme - Server Uploader

Description

This module is used to upload files to a server using Node.js.

Installation

  1. Install the package using the following command:
npm install server-uploader
  1. Once the package is installed, import the module in the required JavaScript file:
const { uploader } = require('server-uploader');

Usage

To upload a file, follow these steps:

  1. Read the file into buffer using fs.readFileSync():
const fs = require('fs');
const buffer = fs.readFileSync('/path/to/file.jpg');
  1. Use uploader() to upload the file:
uploader(buffer)
  .then(url => {
    console.log('Done:', url);
  })
  .catch(error => {
    console.error('Error:', error);
  });

For reference, here are examples of using node-fetch, axios, and fs to read a file into buffer before uploading it using server-uploader.

Using node-fetch for Buffer

const fetch = require('node-fetch');
const { uploader } = require('server-uploader');

let data = await fetch('https://example.com/path/to/file.jpg')
  .then(response => response.buffer())
  .then(buffer => {
    uploader(buffer)
      .then(url => {
        console.log('Done:', url);
      })
      .catch(error => {
        console.error('Error:', error);
      });
  })
  .catch(error => {
    console.error('Error:', error);
  });

Using axios for Buffer

const axios = require('axios');
const { uploader } = require('server-uploader');

let data = await axios.get('https://example.com/path/to/file.jpg', { responseType: 'arraybuffer' })
  .then(response => {
    uploader(response.data)
      .then(url => {
        console.log('Done:', url);
      })
      .catch(error => {
        console.error('Error:', error);
      });
  })
  .catch(error => {
    console.error('Error:', error);
  });

Credits

This module was developed by BOTCAHX.

License

This module is licensed under the MIT License.

server-uploader's People

Contributors

botcahx avatar

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.