flutter - Flutter:MultipartRequest返回403 Forbidden ... CURL工作正常
问题描述
我尝试以下 CURL 命令:
-X PUT \
-H 'Content-Type: application/octet-stream' \
--upload-file ${file_name} \
${url}
将文件上传到 Google 存储 ( https://storage.googleapis.com/...?signature=...&... )。这工作得很好。
但是,当我尝试使用以下 Flutter 代码执行此操作时 - 我收到错误 403(禁止)的响应:
Future<http.Response?> uploadVideo(
{required String uploadURL, required filePath}) async {
try {
ByteData bytes = await rootBundle.load(filePath);
var data =
http.MultipartFile.fromBytes('file', bytes.buffer.asInt64List());
Uri uri = Uri.parse(uploadURL);
var request = http.MultipartRequest(
'PUT',
uri,
);
request.files.add(data);
request.headers.addAll({
HttpHeaders.contentTypeHeader: 'Content-Type: application/octet-stream',
});
http.StreamedResponse response = await request.send();
return await http.Response.fromStream(response);
} on SocketException catch (e) {
showNoInternetError(e);
}
知道为什么会这样吗?uploadURL 与我通过 CURL 发送的相同(很长的字符串,带有签名和 & 符号等)。
非常感谢!!!<3
解决方案
推荐阅读
- android - WebRTC Android,无法获得我应该做什么?
- python - 为什么可以在类中同时覆盖 __eq__ 和 __ne__ ?
- java - 根据驱动程序类型在运行时选择页面对象类
- java - @OneToOne 与三个表之间的共享密钥
- android - 自定义 AutoCompleteTextView 不工作是 android 版本 6.0.1,但它在旧版本上正常工作
- php - 获取作为数组加入的结果
- html - 居中联系表格内容
- ios - 点击时更改 UICollectionViewCell 内的视图不起作用
- xslt - 针对多个正则表达式测试字符串
- node.js - 如何根据查询参数不同的html文件