Skip to content

Commit

Permalink
Fix the bug that saving clipboard images fails
Browse files Browse the repository at this point in the history
  • Loading branch information
doraemonkeys committed Jun 26, 2023
1 parent 2439de0 commit 52447b1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
14 changes: 14 additions & 0 deletions flutter/clipboard/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,20 @@ class _HomePageState extends State<HomePage> {
}
return '复制成功: $content';
}
if (dataType == 'clip-image') {
final imageName =
utf8.decode(response.headers['file-name']![0].codeUnits);
// var file = File('$downloadDir/$fileName');
String filePath;
if (hasImageExtension(imageName)) {
filePath = '$imageDir/$imageName';
} else {
filePath = '$downloadDir/$imageName';
}
var file = File(filePath);
await response.pipe(file.openWrite());
return "已保存到: $filePath";
}
if (dataType == 'files') {
final fileCount = int.parse(response.headers['file-count']![0]);
if (fileCount == 0) {
Expand Down
3 changes: 1 addition & 2 deletions go/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ func sendText(c *gin.Context) {
}

func sendImage(c *gin.Context) {
c.Header("data-type", "files")
c.Header("file-count", "1")
c.Header("data-type", "clip-image")
name := time.Now().Format("20060102150405") + ".png"
c.Writer.Header().Add("file-name", name)
c.Writer.Header().Add("Content-Type", "application/octet-stream")
Expand Down

0 comments on commit 52447b1

Please sign in to comment.