dospace 0.12.12

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');
  await spaces.close();
}

References #

0.12.11 #

  • Switch from http_client package to http package
  • Web compatibility

0.11.9 #

  • Require passing an HTTP Client in the constructor

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/http.dart' as http;

const String region = "nyc3";
const String accessKey = "";
const String secretKey = "";
const String bucketName = "";

main() async {
  dospace.Spaces spaces = new dospace.Spaces(
    region: region,
    accessKey: accessKey,
    secretKey: secretKey,
  );
  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(bucketName);
  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.Client();
    var httpRequest = new http.Request('PUT', Uri.parse(preSignUrl));
    http.StreamedResponse httpResponse = await httpClient.send(httpRequest);
    String body = await utf8.decodeStream(httpResponse.stream);
    print('${httpResponse.statusCode} ${httpResponse.reasonPhrase}');
    print(body);
    await httpClient.close();
  }

  // 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.Client();
    var httpRequest = new http.Request('PUT', Uri.parse(preSignUrl));
    http.StreamedResponse httpResponse = await httpClient.send(httpRequest);
    String body = await utf8.decodeStream(httpResponse.stream);
    print('${httpResponse.statusCode} ${httpResponse.reasonPhrase}');
    print(body);
    await httpClient.close();
  }

  print('done');
}

Use this package as a library

1. Depend on it

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


dependencies:
  dospace: ^0.12.12

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub 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';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
52
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]
76
Learn more about scoring.

We analyzed this package on Jul 17, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:dospace/dospace.dart.

Health suggestions

Fix lib/src/dospace_bucket.dart. (-0.50 points)

Analysis of lib/src/dospace_bucket.dart reported 1 hint:

line 196 col 7: DO use curly braces for all flow control structures.

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 ^0.12.0 0.12.0+2
meta ^1.1.5 1.1.7
xml ^3.0.1 3.5.0
Transitive dependencies
async 2.3.0
charcode 1.1.2
collection 1.14.11
convert 2.1.1
http_parser 3.1.3
path 1.6.2
pedantic 1.8.0+1
petitparser 2.4.0
source_span 1.5.5
string_scanner 1.0.4
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
ini ^2.0.1
test ^1.0.0

Admin