Skip to content

Instantly share code, notes, and snippets.

@mrgulshanyadav
Created June 19, 2020 12:12
Show Gist options
  • Select an option

  • Save mrgulshanyadav/27743e9e4ed7d4f289b2f41774c797f2 to your computer and use it in GitHub Desktop.

Select an option

Save mrgulshanyadav/27743e9e4ed7d4f289b2f41774c797f2 to your computer and use it in GitHub Desktop.
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:dospace/dospace.dart' as dospace;
import 'package:file_picker/file_picker.dart';
class DOSpacesFileUpload extends StatefulWidget {
@override
_DOSpacesFileUploadState createState() => _DOSpacesFileUploadState();
}
class _DOSpacesFileUploadState extends State<DOSpacesFileUpload> {
dospace.Spaces spaces = new dospace.Spaces(
//change with your project's region
region: "nyc3",
//change with your project's accessKey
accessKey: "G3K3EPCZPCVRLQKOYUQE",
//change with your project's secretKey
secretKey: "PLpo3JZ9ARyf7Ash/wOBGRnnpnNvKFVzie86us/nNIk",
);
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SafeArea(
child: Center(
child: RaisedButton(
child: Text('Upload File to DO Spaces'),
onPressed: () async {
File file = await FilePicker.getFile(
type: FileType.custom,
allowedExtensions: ['pdf','txt'],
);
// change with your project's name
String project_name = "project_name";
// change with your project's region
String region = "nyc3";
// change with your project's folder
String folder_name = "taxdocs";
String file_name = file.path.split('/').last;
String etag = await spaces.bucket(project_name).uploadFile(
folder_name + '/' + file_name,
file,
'text/plain',
dospace.Permissions.public);
print('upload: $etag');
String uploaded_file_url = "https://"+project_name+"."+region+".digitaloceanspaces.com/" + folder_name + "/" + file_name;
await spaces.close();
},
)
)
)
)
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment