【问题标题】:How to upload image directly to s3 bucket using flutter web?如何使用flutter web将图像直接上传到s3存储桶?
【发布时间】:2021-07-20 16:36:27
【问题描述】:

我一直在关注本教程https://docs.amplify.aws/lib/storage/getting-started/q/platform/flutter。我有一张使用按钮上传的图片。如何使用 Flutter web 将图像直接上传到 s3 存储桶?我遇到了多个堆栈溢出帖子,其中有答案,但我在任何文件中都找不到正确的答案。我没有后台。我只是想将图像从按钮上传到 s3 存储桶。我只有以下文件。我希望我能得到答案。提前谢谢你。

import 'package:flutter/material.dart';
import 'package:flutter_web_image_picker/flutter_web_image_picker.dart';
void main() {
  runApp(App());
}

class App extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: ImagePickerPage(),
    );
  }
}

class ImagePickerPage extends StatefulWidget {
  @override
  _ImagePickerPageState createState() => _ImagePickerPageState();
}

class _ImagePickerPageState extends State<ImagePickerPage> {
  Image image;
  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        ElevatedButton(
          child: Text("Select Image"),
          onPressed: () async {
            final _image = await FlutterWebImagePicker.getImage;
            setState(() {
              image = _image;
              print(image);
            });
          },
        ),
        CircleAvatar(
          radius: 50,
          backgroundColor: Colors.transparent,
          child: image != null
              ? image
              : Image.asset(
                  'dummy.png',
                  fit: BoxFit.cover,
                ),
        ),
        SizedBox(
          height: 50,
        ),
        ElevatedButton(
          child: Text("Upload to s3 bucket"),
          onPressed: () {
            print(image.semanticLabel);
          },
        ),
      ],
    );
  }
}

【问题讨论】:

    标签: image flutter amazon-s3 flutter-web


    【解决方案1】:

    我发现使用 Flutter Web 将图像直接上传到 s3 存储桶有点困难。但不是直接上传图像,我可以将图像作为文件对象,然后传递给 AWS S3。选择文件时,我可以验证它是否只拍摄图像。这样,我就顺利地将图片上传到s3了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-03-11
      • 2019-06-12
      • 2023-04-03
      • 1970-01-01
      • 2020-12-30
      • 2020-02-14
      • 2016-04-24
      相关资源
      最近更新 更多