ikepu-tp/laravel-file-library

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

This package is auto-updated.

Last update: 2024-05-31 00:22:30 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

HTTP Method URI Action Route Name Description
GET /file/lib index file-library.index Display a list of files in the file library.
GET /file/lib/create create file-library.create Display a form for uploading a new file.
POST /file/lib store file-library.store Upload a file.
GET /file/lib/{fileId} show file-library.show Display details of a specific file.
GET /file/lib/{fileId}/edit edit file-library.edit Display a form for editing a specific file.
PUT /file/lib/{fileId} update file-library.update Update a specific file.
DELETE /file/lib/{fileId} destroy file-library.destroy Delete a specific file.

Note

{fileId} means uuid.

Upload File

Default Route
POST http://your-project.com/file/lib
Key Type Accepted Values Required
files Array<int, File> Y
names Array<int, string> max length: 250 Y
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}
Key Type Accepted Values Required
name string max length: 250 Y

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.