AppFlowy/frontend/appflowy_flutter/lib/shared/cloud_image_checker.dart
Lucas.Xu 26f8bbf7c6
feat: optimize image upload process and display an error message if upload fails (#4679)
* chore: optimize image upload

* feat: show upload image status

* chore: upload the ai image to cloud server
2024-02-19 17:24:47 +08:00

21 lines
590 B
Dart

import 'dart:convert';
import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
import 'package:http/http.dart' as http;
Future<bool> isImageExistOnCloud({
required String url,
required UserProfilePB userProfilePB,
}) async {
final header = <String, String>{};
final token = userProfilePB.token;
try {
final decodedToken = jsonDecode(token);
header['Authorization'] = 'Bearer ${decodedToken['access_token']}';
final response = await http.get(Uri.http(url), headers: header);
return response.statusCode == 200;
} catch (_) {
return false;
}
}