dospace 0.10.7

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 68

DOSpace

Client library to interact with the DigitalOcean Spaces API.

Usage

A simple usage example:

import 'dart:async';
import 'package:dospace/dospace.dart' as dospace;

main() async {
  dospace.Spaces spaces = new dospace.Spaces(
    region: "nyc3",
    accessKey: "7Q7GAFJ4IXHQVLBRXSRX",
    secretKey: "2JLXa9RqPwpavBkC7dt1MHWUDfd6onaXTXTfSYc5eQ0",
  );
  for (String name in await spaces.listAllBuckets()) {
    print('bucket: ${name}');
    dospace.Bucket bucket = spaces.bucket(name);
    await for (dospace.BucketContent content in bucket.listContents(maxKeys: 3)) {
       print('key: ${content.key}');
    }
  }
  String etag = await spaces.bucket('example').uploadFile(
    'README.md', 'README.md', 'text/plain', dospace.Permissions.public);
  print('upload: $etag');
  print('done');
}

References

0.10.7

  • Add support for pre-signed uploads

0.10.6

  • Fixed enum case

0.9.5

  • Adjust version dependency

0.9.4

  • Implement file upload

0.9.3

  • Simplify library usage

0.9.2

  • Initial version

example/dospace_example.dart

import 'dart:convert';
import 'dart:io';

import 'package:crypto/crypto.dart';
import 'package:dospace/dospace.dart' as dospace;
import 'package:http_client/console.dart' as http;

main() async {
  dospace.Spaces spaces = new dospace.Spaces(
    region: "nyc3",
    accessKey: "7Q7GAFJ4IXHQVLBRXSRX",
    secretKey: "2JLXa9RqPwpavBkC7dt1MHWUDfd6onaXTXTfSYc5eQ0",
  );
  for (String name in await spaces.listAllBuckets()) {
    print('bucket: ${name}');
    dospace.Bucket bucket = spaces.bucket(name);
    await for (dospace.BucketContent content
        in bucket.listContents(maxKeys: 3)) {
      print('key: ${content.key}');
    }
  }
  dospace.Bucket bucket = spaces.bucket('example');
  String etag = await bucket.uploadFile(
      'README.md', 'README.md', 'text/plain', dospace.Permissions.public);
  print('upload: $etag');

  // Basic pre-signed URL
  print('list buckets: ${spaces.preSignListAllBuckets()}');

  // Basic pre-signed upload
  {
    String preSignUrl = bucket.preSignUpload('README.md');
    print('upload url: ${preSignUrl}');
    var httpClient = new http.ConsoleClient();
    var httpRequest = new http.Request('PUT', preSignUrl);
    http.Response httpResponse = await httpClient.send(httpRequest);
    BytesBuilder builder = new BytesBuilder(copy: false);
    await httpResponse.body.forEach(builder.add);
    String body = utf8.decode(builder.toBytes());
    print('${httpResponse.statusCode} ${httpResponse.reasonPhrase}');
    print(body);
  }

  // Pre-signed upload with specific payload
  {
    var input = new File('README.md');
    int contentLength = await input.length();
    Digest contentSha256 = await sha256.bind(input.openRead()).first;
    String preSignUrl = bucket.preSignUpload('README.md', contentLength: contentLength, contentSha256: contentSha256);
    print('strict upload url: ${preSignUrl}');
    var httpClient = new http.ConsoleClient();
    var httpRequest = new http.Request('PUT', preSignUrl);
    http.Response httpResponse = await httpClient.send(httpRequest);
    BytesBuilder builder = new BytesBuilder(copy: false);
    await httpResponse.body.forEach(builder.add);
    String body = utf8.decode(builder.toBytes());
    print('${httpResponse.statusCode} ${httpResponse.reasonPhrase}');
    print(body);
  }

  print('done');
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  dospace: ^0.10.7

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:dospace/dospace.dart';
  
Version Uploaded Documentation Archive
0.10.7 Aug 26, 2018 Go to the documentation of dospace 0.10.7 Download dospace 0.10.7 archive
0.9.5 Aug 8, 2018 Go to the documentation of dospace 0.9.5 Download dospace 0.9.5 archive
0.9.4 Aug 7, 2018 Go to the documentation of dospace 0.9.4 Download dospace 0.9.4 archive
0.9.3 Jul 25, 2018 Go to the documentation of dospace 0.9.3 Download dospace 0.9.3 archive
0.9.2 Jul 24, 2018 Go to the documentation of dospace 0.9.2 Download dospace 0.9.2 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
35
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
68
Learn more about scoring.

We analyzed this package on Oct 10, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.4

Platforms

Detected platforms: Flutter, other

Primary library: package:dospace/dospace.dart with components: io.

Health suggestions

Format lib/src/dospace_bucket.dart.

Run dartfmt to format lib/src/dospace_bucket.dart.

Format lib/src/dospace_client.dart.

Run dartfmt to format lib/src/dospace_client.dart.

Format lib/src/dospace_exception.dart.

Run dartfmt to format lib/src/dospace_exception.dart.

Format lib/src/dospace_spaces.dart.

Run dartfmt to format lib/src/dospace_spaces.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.58.0 <3.0.0
crypto ^2.0.6 2.0.6
http_client ^0.5.0 0.5.0
meta ^1.1.5 1.1.6
xml ^3.0.1 3.2.3
Transitive dependencies
charcode 1.1.2
collection 1.14.11
convert 2.0.2
executor 2.1.2
path 1.6.2
petitparser 2.0.2
stack_trace 1.9.3
typed_data 1.1.6
Dev dependencies
test ^1.0.0