1.0.7 • Published 5 months ago

filetsone v1.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

FileTsone 🚀

FileTsone is a lightweight and flexible JavaScript library that enables seamless file uploads to Amazon S3 using multipart uploads with presigned URLs.

🌟 Features

  • Drag & Drop Support: Easily add file uploads via a drag-and-drop interface.
  • Multipart Uploads: Splits large files into chunks for efficient S3 uploads.
  • Customizable Hooks: Tap into key upload events with powerful hooks.
  • Backend Agnostic: You control the backend implementation for flexibility.
  • Your own styling: Make the drag'n'drop div look and feels like you want.

📌 Installation

Simply include the FileTsone bundle in your project:

<script type="module">
    import FileTsone from "./path/to/filetsone.bundle.js";
</script>

🚀 Usage

Basic Example

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>FileTsone Example</title>
</head>
<body>
    <div id="filetsone"></div>
    <div class="submitButton">Upload files</div>
    
    <script type="module">
        import FileTsone from "./path/to/filetsone.bundle.js";

        document.addEventListener("DOMContentLoaded", () => {
            let filetsone = new FileTsone("#filetsone");
            filetsone.setUploadMode('s3');
            filetsone.s3Settings.initiateMultipartUrl = 'http://localhost:8080/api/upload/initiate';
            filetsone.s3Settings.fetchPresignUrl = 'http://localhost:8080/api/upload/presign';
            filetsone.s3Settings.finalizeMultipartUrl = 'http://localhost:8080/api/upload/finalize';
            
            document.querySelector(".submitButton").addEventListener("click", () => filetsone.process());
        });
    </script>
</body>
</html>

🔥 Available Hooks

FileTsone provides a set of hooks that allow you to tap into different stages of the upload process.

Hook NameDescription
processingTriggered when the dropped files are being processed.
droppedTriggered whenever a file is dropped into the tsone.
initiate_multipart_uploadTriggered when initiating a multipart upload.
get_multipart_presign_urlsTriggered when fetching the presigned URLs.
upload_multipart_chunkTriggered when uploading a multipart chunk.

Registering Hooks

filetsone.registerHook('processing', (queue) => {
    console.log("Processing queue", queue);
});

filetsone.registerHook('dropped', (file) => {
    console.log("Dropped file", file);
});

🏗️ Backend API Requirements

Your backend needs to implement the following API endpoints:

1️⃣ Initiate Multipart Upload

Endpoint: POST /api/upload/initiate

ParameterTypeDescription
namestringThe name of the file being uploaded.
  • Headers:
    • Content-Type: application/json
  • Response: JSON object containing a key to identify the upload.

2️⃣ Get Presigned URL

Endpoint: GET /api/upload/presign?requestId={key}&partNumber={partNumber}

Query ParameterTypeDescription
requestIdstringThe unique key returned from the initiate endpoint.
partNumbernumberThe chunk number being uploaded.
  • Response: JSON object containing a url to upload the chunk.

3️⃣ Finalize Multipart Upload

Endpoint: POST /api/upload/finalize

ParameterTypeDescription
request_idstringThe key received from the initiate endpoint.
partsarrayAn array of { PartNumber, ETag } pairs.
  • Headers:
    • Content-Type: application/json
  • Response: Success confirmation.

🎨 Styling FileTsone

#filetsone {
    max-width: 400px;
    height: 200px;
    padding: 25px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-family: "Quicksand", sans-serif;
    font-size: 20px;
    cursor: pointer;
    color: #cccccc;
    border: 4px dashed #009578;
    border-radius: 10px;
}

📜 License

This project is licensed under the MIT License.

1.0.7

5 months ago

1.0.2

5 months ago

1.0.6

5 months ago

1.0.5

5 months ago

1.0.4

5 months ago

1.0.3

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago