fix(upload_image): 修改媒体上传文件
This commit is contained in:
@@ -13,12 +13,35 @@ class VideoBatchUploadPicker {
|
||||
static Future<List<VideoBatchUploadTask>> pickVideos(
|
||||
BuildContext context, {
|
||||
int maxAssets = VideoBatchUploadConfig.maxAssets,
|
||||
}) async {
|
||||
return pickMedia(
|
||||
context,
|
||||
maxAssets: maxAssets,
|
||||
assetType: VideoBatchUploadAssetType.video,
|
||||
);
|
||||
}
|
||||
|
||||
static Future<List<VideoBatchUploadTask>> pickImages(
|
||||
BuildContext context, {
|
||||
int maxAssets = VideoBatchUploadConfig.maxAssets,
|
||||
}) async {
|
||||
return pickMedia(
|
||||
context,
|
||||
maxAssets: maxAssets,
|
||||
assetType: VideoBatchUploadAssetType.image,
|
||||
);
|
||||
}
|
||||
|
||||
static Future<List<VideoBatchUploadTask>> pickMedia(
|
||||
BuildContext context, {
|
||||
int maxAssets = VideoBatchUploadConfig.maxAssets,
|
||||
VideoBatchUploadAssetType assetType = VideoBatchUploadAssetType.video,
|
||||
}) async {
|
||||
final List<AssetEntity>? assets = await AssetPicker.pickAssets(
|
||||
context,
|
||||
pickerConfig: AssetPickerConfig(
|
||||
maxAssets: maxAssets,
|
||||
requestType: RequestType.video,
|
||||
requestType: _requestType(assetType),
|
||||
),
|
||||
);
|
||||
if (assets == null || assets.isEmpty) {
|
||||
@@ -39,10 +62,12 @@ class VideoBatchUploadPicker {
|
||||
tasks.add(
|
||||
VideoBatchUploadTask(
|
||||
id: '${asset.id}_${DateTime.now().microsecondsSinceEpoch}',
|
||||
assetType: assetType,
|
||||
file: file,
|
||||
fileName: _normalizeFileName(asset.title, file.path),
|
||||
fileName: _normalizeFileName(asset.title, file.path, assetType),
|
||||
fileSize: fileSize,
|
||||
duration: asset.duration,
|
||||
duration:
|
||||
assetType == VideoBatchUploadAssetType.video ? asset.duration : 0,
|
||||
thumbnail: thumbnail,
|
||||
),
|
||||
);
|
||||
@@ -50,13 +75,26 @@ class VideoBatchUploadPicker {
|
||||
return tasks;
|
||||
}
|
||||
|
||||
static String _normalizeFileName(String? assetTitle, String path) {
|
||||
static RequestType _requestType(VideoBatchUploadAssetType assetType) {
|
||||
switch (assetType) {
|
||||
case VideoBatchUploadAssetType.image:
|
||||
return RequestType.image;
|
||||
case VideoBatchUploadAssetType.video:
|
||||
return RequestType.video;
|
||||
}
|
||||
}
|
||||
|
||||
static String _normalizeFileName(
|
||||
String? assetTitle,
|
||||
String path,
|
||||
VideoBatchUploadAssetType assetType,
|
||||
) {
|
||||
final String title = (assetTitle ?? '').trim();
|
||||
if (title.isNotEmpty) {
|
||||
return title;
|
||||
}
|
||||
final List<String> segments = path.split(Platform.pathSeparator);
|
||||
final String fileName = segments.isEmpty ? '' : segments.last.trim();
|
||||
return fileName.isEmpty ? 'video.mp4' : fileName;
|
||||
return fileName.isEmpty ? assetType.defaultFileName : fileName;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user