Mohammed Yahya
Mohammed Yahya

Reputation: 29

uploading image to backed from flutter error 401

Flutter image upload to laravel backed is returning 401 error. My backed have database fields name, middelName , and profilePic The api works fine on postman but on flutter picking image from gallery and camera its not working i have implemented internet permission on all manifests i used Vpn but error 401 here is flutter code

Future uploadImage() async{
    final uri =Uri.parse("https://www.compaytarining.com/api/exrecise2/");
    var request =http.MultipartRequest('POST',uri);
    request.fields["name"]=nameController.text;
    request.fields["middelName"] = mnameController.text;
    var pic= await http.MultipartFile.fromPath("profilePic", _image.path);
   
    request.files.add(pic);
    var response = await request.send();
  
    print(response.statusCode);
    if(response.statusCode==200)
      {

        print('ImageUploaded');
      }
    else
      {
        print("Error");
       
      }
}

Gallery Image

File _image;
  final picker=ImagePicker();
Future getImage() async
  {
    final pickedImage=await picker.getImage(source: ImageSource.gallery);
    setState(() {
      _image=File(pickedImage.path);
    });
  }

Many thanks

Upvotes: 0

Views: 622

Answers (1)

Khal
Khal

Reputation: 225

Hello check it may be error is from your response which is when you return an api response may be u set it to return 401.

Upvotes: 1

Related Questions