-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to upload an image(s) to Google Cloud #167
Comments
If you use FormData, the request contentType will be set to "multipart/form-data" (ignoring options.contentType), there are two ways to upload file to Google cloud.
var imgFile=new File("");
String savePath="";
String token="xxx";
// Sending stream
await dio.post(
"https://www.googleapis.com/upload/storage/v1/b/opine-world/o?uploadType=media&name=$savePath",
data: imgFile.openRead(), // Post with Stream<List<int>>
options: Options(
headers: {
HttpHeaders.contentTypeHeader: ContentType.text,
HttpHeaders.contentLengthHeader: imgFile.lengthSync(),
// Set content-length
HttpHeaders
.authorizationHeader: "Bearer $token"
},
),
);
|
For anyone who wants to support cross platform (Web/Desktop & Mobile) here is an alternative; since Web files don't always have path included and only name.
|
@ollyde but will the fileUpload = await MultipartFile.fromFile(file.path!, filename: file.name); load the whole file in memory? |
Hi, I am trying to upload an image of jpeg file format to Google Cloud but I keep on getting one of my metatdata responses as
contentType: multipart/form-data; boundary=--dioBoundary&Happycoding-3148554670
instead of"contentType": "image/jpeg",
, thus corrupting the file in the cloudThis is my source reference
I have seen your example in , but i wish there could be on uploading to Google Cloud.
Steps to Reproduce
Logs
The text was updated successfully, but these errors were encountered: