GithubHelp home page GithubHelp logo

yusriltakeuchi / dolinode_space Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 285 KB

License: MIT License

Kotlin 0.20% Swift 1.85% Objective-C 0.06% Dart 29.63% CMake 29.77% C++ 33.33% C 2.27% HTML 2.90%

dolinode_space's Introduction

Client library to interact with the DigitalOcean & Linode Spaces API.

Features

  • Upload files
  • Get list files from buckets

Usage

Setup space instance

/// Initialize space
DOLinodeSpaces spaces = DOLinodeSpaces(
    region: "ap-south-1",
    accessKey: "accessKey",
    secretKey: "secretKey",
    provider: Providers.linodeobject,
);

A simple usage to upload file to specific bucket

/// Uploading file to space and
/// get direct link to file
Future<String> uploadFile(File file) async {
    String bucket = "example"
    String filename = file.path.split('/').last.split(".").first;
    /// Encrypting filename using base64
    /// and use the value as the key in spaces
    String fileKey = "images/${base64.encode(utf8.encode(filename))}${path.extension(file.path)}";

    String? eTag = await spaces?.bucket(bucket)
        .uploadFile(fileKey, file, "image/jpeg", Permissions.public);
    List<BucketContentModel> contents =
        await spaces!.bucket(bucket).listContents();
    return contents.firstWhere((item) => item.eTag == eTag).url ?? "";
}

final url = await uploadFile(File("/images/image-example.jpg"));
debugPrint("Uploaded url: $url");

A simple usage to get list files from bucket

/// Get list file from specific bucket
Future<List<BucketContentModel>> listFile() async {
    String bucket = "example"
    return await spaces!.bucket(bucket).listContents();
}

/// Get list file from specific bucket
List<BucketContentModel> contents = await listFile();
for (var content in contents) {
    debugPrint("- ${content.url}");
}

Additional information

dolinode_space's People

Contributors

yusriltakeuchi avatar

Stargazers

 avatar

Watchers

 avatar

dolinode_space's Issues

SignatureDoesNotMatch

{ statusCode: 403, reasonPhrase: "Forbidden", responseBody: "SignatureDoesNotMatchtx0000000000000176be8d8-0063729f72-213ec593-sfo3a213ec593-sfo3a-sfo3-zg01" })

I have this error when i make a request for upload a file .png, i searched in foros a lot but i can't fixed, would you help me?

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.