JSPM

save-file-npm

1.0.0
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • Downloads 3
    • Score
      100M100P100Q40414F
    • License MIT

    With this incredible package, managing file uploads has never been easier! You can now simply use the saveFile() method with your inputs and directory, and watch as it handles all the logic for you. The inputs can be of any type - file-object (image, PDF, video, exe, and more), HTTPS URLs, and even base64 data. The saveFile() method takes care of all the intricate details, leaving you with more time to focus on other aspects of your project. Give it a try and experience the convenience and ease of use that this package has to offer!

    Package Exports

    • save-file-npm
    • save-file-npm/index.js

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (save-file-npm) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    Save File Functionality

    This function allows you to save a file to a specified folder on the server. It accepts various input types including URLs, base64 strings, and file objects.

    Installation

    npm install save-file-npm

    Live DEMO:

    Usage

    saveFile(source, folder, fileName?, req?) Uploads a file from the given source to the specified folder. The fileName parameter is optional and can be used to set a custom name for the uploaded file. The req parameter is also optional and can be used to get the full URL of the uploaded file.

    Parameters

    The saveFile function takes in the following parameters:

    • file: This can be an object, string, or base64 data representing the file you want to save. It is a required parameter.
    • folderName: This is a string representing the name of the folder where the file will be saved. It is a required parameter.
    • fileName (optional): This is an optional parameter that allows you to set a custom file name for the saved file.
    • req (optional): This is an optional parameter that can be used to retrieve the current full file URL if needed. Examples

    Here are some examples of how to use the saveFile function:

    Import the "getColumnSum" function into your component or service by adding the following code:

    const saveFile = require('save-file-npm');

    const saveFile = require('save-file-npm');
    
    // Upload a file from a URL to a folder
        saveFile('https://pbs.twimg.com/profile_images/1410074091965403139/IqExKETZ_400x400.jpg', 'new_dir_1')
        .then(result => {
            console.log(result);
        })
        .catch(err => console.log(err));
    
    // Upload a file from a URL to a folder and get the full URL
        saveFile('https://pbs.twimg.com/profile_images/1410074091965403139/IqExKETZ_400x400.jpg', 'new_dir_1', null, req)
        .then(result => {
            console.log(result);
        })
        .catch(err => console.log(err));
    
    // Upload a file from a base64-encoded string to a folder
        saveFile(base64, 'new_dir_1')
        .then(result => {
            console.log(result);
        })
        .catch(err => console.log(err));
    
    // Upload a file from a file object to a folder
        const fileObject = req.file;
        saveFile(fileObject, 'new_dir_1')
        .then(result => {
            console.log(result);
        })
        .catch(err => console.log(err));
    
    // Upload a file from a file object to a folder and get the full URL
        saveFile(fileObject, 'new_dir_2', null, req)
        .then(result => {
            console.log(result);
        })
        .catch(err => console.log(err));
    
    // Upload a file from a URL to a folder with a custom file name and get the full URL
        saveFile('https://pbs.twimg.com/profile_images/1410074091965403139/IqExKETZ_400x400.jpg', 'new_dir_2', 'new-logo-name', req)
        .then(result => {
            console.log(result);
        })
        .catch(err => console.log(err));

    Conclusion

    This saveFile function is a simple and effective way to save files to a server using a variety of input types. If you have any questions or issues using this function, please don't hesitate to reach out for support.