My API requirement is
URL: /user/upload-profile-image
method= POST
header--
Accesstoken: "access_token"
content-type = multipart/form-data
This is my code:
Future getUploadImg(File _image) async {
String apiUrl = '$_apiUrl/user/upload-profile-image';
final length = await _image.length();
final request = new http.MultipartRequest('POST', Uri.parse(apiUrl))
..files.add(new http.MultipartFile('avatar', _image.openRead(), length));
http.Response response = await http.Response.fromStream(await request.send());
print("Result: ${response.body}");
return JSON.decode(response.body);
}
In the Flutter Event Calendar, you can customize the header and view header and it can be achieved by hiding headers and placing Container, Row, and Column widgets of the flutter. STEP 1: Set the `HeaderHeight` and `ViewHeaderHeight` properties to `0` to hide the default headers.
I have to use the basename() function to get the image file path. That image file is memory image file.To use that function you need to import the path package which I have mentioned before. Add this into your button function. After you select image hit the upload button.
It is commonly used by HTTP clients to upload files to the Server. In this example, first, we choose the image from the gallery using ImagePicker and then upload images to the server using PHP. First, add the image_picker Flutter package as a dependency by adding the following line in your pubspec.yaml file.
a) To add images, write the following code: flutter: assets: - assets/images/yourFirstImage.jpg - assets/image/yourSecondImage.jpg. b) If you want to include all the images of the assets folder then add this: flutter: assets: - assets/images/. Note: Take care of the indentation, assets should be properly indented to avoid any error.
First, add the image_picker Flutter package as a dependency by adding the following line in your pubspec.yaml file. Now write the function for pick image from Gallery. The optional parameter imageQuality accepts any value between 0 to 100, you can adjust it according to the size and quality required by your app.
Common types of assets include static data (for example, JSON files), configuration files, icons, and images (JPEG, WebP, GIF, animated WebP/GIF, PNG, BMP, and WBMP). Flutter uses the pubspec.yaml file, located at the root of your project, to identify assets required by an app.
Can you try to add headers
like below
Map<String, String> headers = { "Accesstoken": "access_token"};
final multipartRequest = new http.MultipartRequest('POST', Uri.parse(apiUrl))
multipartRequest.headers.addAll(headers);
multipartRequest.files.add(..)
var request = http.MultipartRequest(
"POST",
Uri.parse(
"${Urls().url}/support/tenant/register",
),
);
//add text fields
request.headers["authorization"]=userToken;
request.fields["type"] = type;
request.fields["note"] = note;
for (var item in path) {
var ext = item.split('.').last;
var pic = await http.MultipartFile.fromPath("images", item, contentType: MediaType('image', ext));
request.files.add(pic);
}
//add multipart to request
var response = await request.send();
var responseData = await response.stream.toBytes();
var responseString = String.fromCharCodes(responseData);
var d = jsonDecode(responseString);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With