ikepu-tp/laravel-file-library

v1.3.0 2024-03-02 04:53 UTC

This package is auto-updated.

Last update: 2024-10-31 00:29:00 UTC


README

This is a file management library for Laravel.

How to use

Install

composer require ikepu-tp/larave-file-library

Publish configuration etc

php artisan vendor:publish --provider="ikepu_tp\FileLibrary\FileLibraryServiceProvider"

Routing

Note

{fileId} means uuid.

Upload File

Default Route
POST http://your-project.com/file/lib
Original Route
class FileController extends Controller
{
    public function store(Request $request)
    {
        $guard = config("file-library.guard");
        $files = \ikepu_tp\FileLibrary\app\Services\FileLibraryService::upload(
            $guard, 
            $request->file("files", []), 
            $request->input("names", [])
        );

        return back()->with("status", "File uploaded.");
    }
}

Edit File

PUT http://your-project.com/file/lib/{fileId}

API Documentation

FileLibraryController

FileLibraryResource

{
  "fileId": "string",
  "name": "string",
  "url": "string",
  "mime_type": "string",
  "created_at": "string",
  "updated_at": "string"
}

index

Display a list of files in the file library.

GET http://your-project.com/file/lib
index Sample
{
    "status":{
        "result":true,
        "code":200,
    },
    "payloads":{
        "meta": {
            "currentPage": 1,
            "lastPage": 1,
            "length": 1,
            "getLength": 0,
            "per":1,
        },
        "items":[
                {
                    "fileId": "uuid",
                    "name": "file name",
                    "url": "http://your-project.com/file/lib/uuid",
                    "mime_type": "application/json",
                    "created_at": "2024-01-01T00:00:00Z",
                    "updated_at": "2024-01-01T00:00:00Z"
                }
        ]
    }
}

store

Upload a file.

POST http://your-project.com/file/lib
store Sample
{
    "files": [
        "FILE BINARY",
    ],
    "names":[
        "file name",
    ]
}
{
    "status":{
        "result":true,
        "code":201,
    },
    "payloads": [
        {
            "fileId": "uuid",
            "name": "file name",
            "url": "http://your-project.com/file/lib/uuid",
            "mime_type": "application/json",
            "created_at": "2024-01-01T00:00:00Z",
            "updated_at": "2024-01-01T00:00:00Z"
        }
    ]
}

show

Display details of a specific file.

GET http://your-project.com/file/lib/{fileId}

update

Update a specific file.

PUT http://your-project.com/file/lib/{fileId}

destroy

Delete a specific file.

DELETE http://your-project.com/file/lib/{fileId}

Contributing

We welcome contributions to the project! You can get involved through the following ways:

Issue: Use for bug reports, feature suggestions, and more.

Pull Requests: We encourage code contributions for new features and bug fixes.

License

See LICENSE.