Secure pulling & ulouding files in minio
This commit is contained in:
@@ -2,8 +2,13 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';
|
import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';
|
||||||
|
|
||||||
class BuildFileView extends StatefulWidget {
|
class BuildFileView extends StatefulWidget {
|
||||||
final String pdfLink;
|
final String link;
|
||||||
const BuildFileView({super.key, required this.pdfLink});
|
final String path;
|
||||||
|
const BuildFileView({
|
||||||
|
super.key,
|
||||||
|
required this.link,
|
||||||
|
required this.path,
|
||||||
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<BuildFileView> createState() => _BuildFileViewState();
|
State<BuildFileView> createState() => _BuildFileViewState();
|
||||||
@@ -12,14 +17,16 @@ class BuildFileView extends StatefulWidget {
|
|||||||
class _BuildFileViewState extends State<BuildFileView> {
|
class _BuildFileViewState extends State<BuildFileView> {
|
||||||
late PdfViewerController pdfViewerController = PdfViewerController();
|
late PdfViewerController pdfViewerController = PdfViewerController();
|
||||||
|
|
||||||
String getExtType(String pdfLink) {
|
String getExtType(String path) {
|
||||||
//print(pdfLink.split(".")[1]);
|
//print(pdfLink.split(".")[1]);
|
||||||
return pdfLink.split(".").last;
|
return path.split(".").last;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (getExtType(widget.pdfLink).toLowerCase() == "pdf") {
|
print(
|
||||||
|
"${widget.link} ================================================================");
|
||||||
|
if (getExtType(widget.path).toLowerCase() == "pdf") {
|
||||||
//print(widget.pdfLink);
|
//print(widget.pdfLink);
|
||||||
return SizedBox(
|
return SizedBox(
|
||||||
width: 700,
|
width: 700,
|
||||||
@@ -27,7 +34,7 @@ class _BuildFileViewState extends State<BuildFileView> {
|
|||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
child: SfPdfViewer.network(
|
child: SfPdfViewer.network(
|
||||||
widget.pdfLink,
|
widget.link,
|
||||||
controller: pdfViewerController,
|
controller: pdfViewerController,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -39,7 +46,7 @@ class _BuildFileViewState extends State<BuildFileView> {
|
|||||||
return InteractiveViewer(
|
return InteractiveViewer(
|
||||||
maxScale: 5.0,
|
maxScale: 5.0,
|
||||||
//minScale: 0.,
|
//minScale: 0.,
|
||||||
child: Image.network(widget.pdfLink),
|
child: Image.network(widget.link),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,36 @@ class BuildFilesList extends StatefulWidget {
|
|||||||
class _BuildFilesListState extends State<BuildFilesList> {
|
class _BuildFilesListState extends State<BuildFilesList> {
|
||||||
int indexOn = 0;
|
int indexOn = 0;
|
||||||
final baseAPI = AppEnviroment.baseApiUrl;
|
final baseAPI = AppEnviroment.baseApiUrl;
|
||||||
|
String fileUrl = "";
|
||||||
|
|
||||||
|
Future<String> getFileUrlApiCall(String filePath) async {
|
||||||
|
var url;
|
||||||
|
if (AppEnviroment.getEnv() == "Dev") {
|
||||||
|
url = "$baseAPI/minio/pull/file/$filePath/dev";
|
||||||
|
} else {
|
||||||
|
url = "$baseAPI/minio/pull/file/$filePath/prod";
|
||||||
|
}
|
||||||
|
//print(url);
|
||||||
|
var response = await http.get(Uri.parse(url));
|
||||||
|
// print("here1");
|
||||||
|
//print(response.statusCode);
|
||||||
|
|
||||||
|
if (response.statusCode == 200) {
|
||||||
|
//print("here2");
|
||||||
|
String body = response.body;
|
||||||
|
//print(body);
|
||||||
|
//print("here3");
|
||||||
|
var decodedData = jsonDecode(body);
|
||||||
|
//print("Dedoced: ${decodedData['minioURL']}");
|
||||||
|
|
||||||
|
return decodedData['minioURL'];
|
||||||
|
//AppUser u = AppUser.fromJson(decodedData);
|
||||||
|
// print(u.email);
|
||||||
|
//return "AlometThere";
|
||||||
|
} else {
|
||||||
|
throw Exception("Error: GetUserData status code ${response.statusCode}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> deleteFileApiCall(String filePath, int fileID) async {
|
Future<void> deleteFileApiCall(String filePath, int fileID) async {
|
||||||
// delete file from minio
|
// delete file from minio
|
||||||
@@ -101,7 +131,7 @@ class _BuildFilesListState extends State<BuildFilesList> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void viewFilePopUp(String fileName, String filePath, int fileID) {
|
void viewFilePopUp(String fileName, String filePath, int fileID, String url) {
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
barrierDismissible: false,
|
barrierDismissible: false,
|
||||||
@@ -154,15 +184,18 @@ class _BuildFilesListState extends State<BuildFilesList> {
|
|||||||
const SizedBox(height: 25.0),
|
const SizedBox(height: 25.0),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: BuildFileView(
|
child: BuildFileView(
|
||||||
pdfLink:
|
link: url,
|
||||||
"${AppEnviroment.baseFileUrl}/mih/$filePath")),
|
path: filePath,
|
||||||
|
//pdfLink: '${AppEnviroment.baseFileUrl}/mih/$filePath',
|
||||||
|
)),
|
||||||
SizedBox(
|
SizedBox(
|
||||||
width: 300,
|
width: 300,
|
||||||
height: 100,
|
height: 100,
|
||||||
child: MyButton(
|
child: MyButton(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
html.window.open(
|
html.window.open(
|
||||||
'${AppEnviroment.baseFileUrl}/mih/$filePath',
|
url,
|
||||||
|
// '${AppEnviroment.baseFileUrl}/mih/$filePath',
|
||||||
'download');
|
'download');
|
||||||
},
|
},
|
||||||
buttonText: "Dowload",
|
buttonText: "Dowload",
|
||||||
@@ -231,12 +264,20 @@ class _BuildFilesListState extends State<BuildFilesList> {
|
|||||||
Icons.arrow_forward,
|
Icons.arrow_forward,
|
||||||
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||||
),
|
),
|
||||||
onTap: () {
|
onTap: () async {
|
||||||
|
await getFileUrlApiCall(widget.files[index].file_path)
|
||||||
|
.then((urlHere) {
|
||||||
|
//print(url);
|
||||||
|
setState(() {
|
||||||
|
fileUrl = urlHere;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
viewFilePopUp(
|
viewFilePopUp(
|
||||||
widget.files[index].file_name,
|
widget.files[index].file_name,
|
||||||
widget.files[index].file_path,
|
widget.files[index].file_path,
|
||||||
widget.files[index].idpatient_files,
|
widget.files[index].idpatient_files,
|
||||||
);
|
fileUrl);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import 'package:patient_manager/objects/appUser.dart';
|
|||||||
import 'package:patient_manager/objects/files.dart';
|
import 'package:patient_manager/objects/files.dart';
|
||||||
import 'package:supertokens_flutter/http.dart' as http;
|
import 'package:supertokens_flutter/http.dart' as http;
|
||||||
import 'package:http/http.dart' as http2;
|
import 'package:http/http.dart' as http2;
|
||||||
|
import 'package:supertokens_flutter/supertokens.dart';
|
||||||
|
|
||||||
import '../objects/patients.dart';
|
import '../objects/patients.dart';
|
||||||
|
|
||||||
@@ -132,18 +133,23 @@ class _PatientFilesState extends State<PatientFiles> {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
var token = await SuperTokens.getAccessToken();
|
||||||
|
//print(t);
|
||||||
//print("here1");
|
//print("here1");
|
||||||
var request = http2.MultipartRequest(
|
var request = http2.MultipartRequest(
|
||||||
'POST', Uri.parse("${AppEnviroment.baseApiUrl}/minio/upload/file/"));
|
'POST', Uri.parse("${AppEnviroment.baseApiUrl}/minio/upload/file/"));
|
||||||
request.headers['accept'] = 'application/json';
|
request.headers['accept'] = 'application/json';
|
||||||
request.fields['app_id'] = widget.selectedPatient.app_id;
|
request.headers['Authorization'] = 'Bearer $token';
|
||||||
request.headers['Content-Type'] = 'multipart/form-data';
|
request.headers['Content-Type'] = 'multipart/form-data';
|
||||||
|
request.fields['app_id'] = widget.selectedPatient.app_id;
|
||||||
request.files.add(await http2.MultipartFile.fromBytes('file', file.bytes!,
|
request.files.add(await http2.MultipartFile.fromBytes('file', file.bytes!,
|
||||||
filename: file.name.replaceAll(RegExp(r' '), '-')));
|
filename: file.name.replaceAll(RegExp(r' '), '-')));
|
||||||
//print("here2");
|
//print("here2");
|
||||||
var response1 = await request.send();
|
var response1 = await request.send();
|
||||||
//print("here3");
|
//print("here3");
|
||||||
//print(response1.statusCode);
|
print(response1.statusCode);
|
||||||
|
print(response1.toString());
|
||||||
if (response1.statusCode == 200) {
|
if (response1.statusCode == 200) {
|
||||||
//print("here3");
|
//print("here3");
|
||||||
var fname = file.name.replaceAll(RegExp(r' '), '-');
|
var fname = file.name.replaceAll(RegExp(r' '), '-');
|
||||||
|
|||||||
Reference in New Issue
Block a user