dospace 0.12.12

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

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 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.12.12 Dec 1, 2018 Go to the documentation of dospace 0.12.12 Download dospace 0.12.12 archive
0.11.10 Nov 30, 2018 Go to the documentation of dospace 0.11.10 Download dospace 0.11.10 archive
0.11.9 Nov 30, 2018 Go to the documentation of dospace 0.11.9 Download dospace 0.11.9 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]
56
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]
78
Learn more about scoring.

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

  • Dart: 2.1.0
  • pana: 0.12.7

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:dospace/dospace.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 ^0.12.0 0.12.0
meta ^1.1.5 1.1.6
xml ^3.0.1 3.2.3
Transitive dependencies
async 2.0.8
charcode 1.1.2
collection 1.14.11
convert 2.0.2
http_parser 3.1.3
path 1.6.2
petitparser 2.0.2
source_span 1.4.1
string_scanner 1.0.4
typed_data 1.1.6
Dev dependencies
ini ^2.0.1
test ^1.0.0