我正在开发一个将图像上传到Amazon S3 存储桶的应用程序,我希望能够获取有关上传状态的进度,而不是仅仅显示 Spinner 。
我正在使用Package:http中的MultipartRequest上传文件。我已成功上传文件,但我想获取正在上传的文件的进度。我怎样才能做到这一点?我当前的代码看起来像这样。
static Future<bool> uploadFile({@required userId, @required albumId, @required data, @required fileName}) async{
const _accessKeyId = 'AKIAVV**********';
const _secretKeyId = 'iyBmdn6v***************************';
const _region = 'us-east-1';
const _s3Endpoint = 'https://myalbums-content.s3.amazonaws.com';
final file = data;
var stream = new http.ByteStream(DelegatingStream.typed(file.openRead()));
final length = await file.length();
final uri = Uri.parse(_s3Endpoint);
final req = http.MultipartRequest("POST", uri);
var multipartFile = http.MultipartFile('file', stream, length,
contentType: new MediaType('image','JPG'));
final policy = Policy.fromS3PresignedPost(userId.toString() +'/'+ albumId.toString() …Run Code Online (Sandbox Code Playgroud) 我正在编写一个将图像上传到服务器的应用程序,我不希望仅显示微调框,而是希望能够获得该上传状态的进度。
此外,我想这样做而不使用Multipart表单数据。这是我当前正在使用的代码-但它似乎因管道中断而停滞了,对于是否将数据发送到服务器,我的反馈为零:
Future<String> _uploadFile(File assetFile) async {
final url = <removed>;
final stream = await assetFile.openRead();
int length = assetFile.lengthSync();
final client = new HttpClient();
final request = await client.postUrl(Uri.parse(url));
request.headers.add(HttpHeaders.CONTENT_TYPE, "application/octet-stream");
request.contentLength = length;
await request.addStream(stream);
final response = await request.close();
// response prociessing.
}
Run Code Online (Sandbox Code Playgroud)
是否可以将大数据作为流发送而无需将其读入内存,并且可以使用当前的dart / flutter API在上传中取得进展吗?