jonataslaw / get_server

A backend server that makes it possible to program with Flutter syntax and reuse existing code
Apache License 2.0
475 stars 43 forks source link

File Upload some time get unreadable image #77

Open vimptech-git opened 2 years ago

vimptech-git commented 2 years ago

import 'dart:io';

import 'package:get_server/get_server.dart';

class FileuploadView extends GetView { @override Widget build(BuildContext context) { return MultiPartWidget( builder: (context, upload) { final path = 'images/123.jpg'; var p = File(path); p.writeAsBytes(upload!.data);

    return Json({
      'nameFile': upload.name,
      'mimeType': upload.mimeType,
      'fileBase64': upload.data,
    });
  },
);

} }

jonataslaw commented 2 years ago

Try this: Uint8List bytes = base64.decode(upload!.data); ... p.writeAsBytes(bytes);

vimptech-git commented 2 years ago

class FileuploadView extends GetView { @override Widget build(BuildContext context) { return MultiPartWidget( builder: (context, upload) { final path = 'images/123.jpg'; var p = File(path); Uint8List bytes = base64.decode(upload!.data); p.writeAsBytes(bytes);

    return Json({'filename': upload.data});
  },
);

} } /////////////////////////////////////////////////////////// showing following error Unhandled exception: type 'Uint8List' is not a subtype of type 'String' ///////////////////////////////////////////////// Note:- at the time of testing fist time image successfully upload .. then second time file uploaded successfully but can't open file then we try again and again then some time image upload success.. Pls Help me ..... my suggestion can i use awit p.writeAsBytes(bytes); in this time builder method show error due to async /////////////////////////////////////////////////////////

[image: Capture.JPG]

On Thu, Mar 10, 2022 at 10:21 PM Jonny Borges @.***> wrote:

Try this: Uint8List bytes = base64.decode(upload!.data); ... p.writeAsBytes(bytes);

— Reply to this email directly, view it on GitHub https://github.com/jonataslaw/get_server/issues/77#issuecomment-1064280321, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANO4T67VPIVA3DWHWHTWFK3U7ISCTANCNFSM5QNAZ5EA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

tang85 commented 2 years ago

Succeed when the image has small size .Always failed when the image was big(>2M). This can be reproduced as image in postman.

截屏2022-03-15 上午8 58 21

and codes as :

MultiPartWidget(
        name: 'image',
        builder: (context, upload) 
          if (upload != null) {
            var data = upload.data;
            print('---receive---${data.length}');
            File(upload.name ?? 'empty_name.png').writeAsBytesSync(data);
            return Json({'name': upload.name ?? 'empty_name.png'});
          } else {
            return Json({'name': 'error'});
          }
        });