insert data with multipart request- response.statusCode- 415

386 views
Skip to first unread message

Raman Plaha

unread,
Feb 8, 2021, 1:37:05 AM2/8/21
to Flutter Development (flutter-dev)
hello everyone!
I tried to insert data in through api and multipart request, when i print response status code I get 415,
body is like--
{
    "respOject": {
        "adTitle": "PostElectronics",
        "osofModel": "windows",
        "ramofModel":"4gb",
        "screenSize":"32inch",
        "yearofPurchase": "2019",
        "graphics": "2gb",
        "processor": "i3",
        "frontCamera": "10mp",
        "backCamera": "20mp",
        "sellingPrice":"4000",
        "isNegotiate":true,
        "description":"postproductelectronics",
        "color":"red",
        "isNumberPrivate":true,
        "password":"123456",
        "productId":{
            "productId":4
        },
        "idelectronicsaccessoriesList":[
                   {
                       "electronicsaccessoriesId":1
                   }
        ],
        
        "brandId":{
            "brandId":35
        },
        "productConditionId":{
            "productConditionId":4
        },
        "customerId": {
            "customerId": 1,
            "mobileNumber": "1245454554"
        },
        "adsTypeId": {
            "inActivePeriod": 5,
            "adsTypeId": 7,
            "adsTypeName": "Free"
        },
        "roleId": {
            "roleId": 2
        },
        "localityId": {
            "localityId": 1
        },
        "sellerId": {
            "sellerId": 67
        },
        "sellerTypeId": {
            "sellerTypeId": 1
        },
        "subCategoryId": {
            "subCategoryId": 7,
            "categoryId": {
                "categoryId": 3
            }
        }
        
        
    },
    
    "resplist": [
        {
            "filename": "atiflogo.jpg",
            "filetype": "image/jpeg",
            "value": "/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxMTEhUTExMVFR…5V1dUu6f+Q/Tj4HNnZ9teCIOyFFORaHYKGurn1y8jUI+D/9k=",
            "imagefileName": "educationImage"
        }
    ],
    "languageName": "English"
}

 api working fine in postman and get 

{
    "statusCode": 0,
    "message": "Electronics saved successfully",
    "extraVariable": null,
    "authTOken": null,
    "respOject": null,
    "resplist": null
}

but not in flutter
this is my code - 

var uri = Uri.parse(
"https://www.xyzzz.com/xyzz/mobile/insertpostproductelectronic");
var request = new http.MultipartRequest("POST", uri);
for (var file in files) {
String fileName = file.path.split('/').last;
var stream = new http.ByteStream(DelegatingStream.typed(file.openRead()));
var length = await file.length();
var multipartFileSign =
new http.MultipartFile('resplist', stream, length, filename: fileName);
request.files.add(multipartFileSign);
}
Map<String, String> headers = {
'Accept':'application/json',
'Content-Type': 'application/json; charset=UTF-8',
'Charset': 'utf-8'
};
request.headers.addAll(headers);
request.fields['adTitle'] = widget.adtitle;
request.fields['osofModel'] = "";
request.fields['ramofModel'] = "";
request.fields['screenSize'] = "";
request.fields['yearofPurchase'] = widget.yearofpur;
request.fields['graphics'] = "";
request.fields['processor'] = widget.processor;
request.fields['frontCamera'] = widget.frontcamera;
request.fields['backCamera'] = widget.backcamera;
request.fields['sellingPrice'] = widget.sellingprice;
request.fields['isNegotiate'] = widget.negotiate.toString();
request.fields['description'] = widget.description;
request.fields['color'] = widget.color;
request.fields['isNumberPrivate'] = "";
request.fields['password'] = "";
request.fields['productId'] = widget.prodname;
request.fields['electronicsaccessoriesId'] ='';
request.fields['brandId'] = widget.brandid;
request.fields['productConditionId'] = widget.prodcondition;
request.fields['customerId'] = widget.customer.toString();
request.fields['mobileNumber'] = widget.cotact.toString();
request.fields['inActivePeriod'] = _inActivePeriod.toString();
request.fields['adsTypeId'] = _adsTypeId.toString();
request.fields['adsTypeName'] = _adsTypeName;
request.fields['roleId'] = "";
request.fields['localityId'] = widget.locality;
request.fields['sellerId'] = "";
request.fields['subCategoryId'] = widget.sub_catId.toString();
request.fields['categoryId'] = widget.categoryid.toString();
request.fields['languageName'] = "";
var response = await request.send();
print(response.statusCode);
response.stream.transform(utf8.decoder).listen((value) {
var res = jsonDecode(value);
print(res);
if (response.statusCode == 200) {
openAlertBox(res["message"]);
print("payment done - "+res);
} else {
closeAlertBox(res["message"]);
print("error in submit");
}
});

Error log --

Performing hot reload...
Syncing files to device AOSP on IA Emulator...
Reloaded 36 of 885 libraries in 4,875ms.
I/flutter ( 6176): 415
E/flutter ( 6176): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: FormatException: Unexpected character (at character 1)
E/flutter ( 6176): <!DOCTYPE html><html><head><title>Apache Tomcat/8.5.6 - Error report</title...
E/flutter ( 6176): ^
E/flutter ( 6176): 
E/flutter ( 6176): #0      _ChunkedJsonParser.fail (dart:convert-patch/convert_patch.dart:1404:5)
E/flutter ( 6176): #1      _ChunkedJsonParser.parseNumber (dart:convert-patch/convert_patch.dart:1271:9)
E/flutter ( 6176): #2      _ChunkedJsonParser.parse (dart:convert-patch/convert_patch.dart:936:22)
E/flutter ( 6176): #3      _parseJson (dart:convert-patch/convert_patch.dart:40:10)
E/flutter ( 6176): #4      JsonDecoder.convert (dart:convert/json.dart:505:36)
E/flutter ( 6176): #5      JsonCodec.decode (dart:convert/json.dart:156:41)
E/flutter ( 6176): #6      jsonDecode (dart:convert/json.dart:96:10)
E/flutter ( 6176): #7      _PaymentforAdsState.submitpayment.<anonymous closure> (package:etroc/Screens/paymentForPostAds.dart:1122:21)
E/flutter ( 6176): #8      _rootRunUnary (dart:async/zone.dart:1198:47)
E/flutter ( 6176): #9      _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter ( 6176): #10     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
E/flutter ( 6176): #11     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:357:11)
E/flutter ( 6176): #12     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:285:7)
E/flutter ( 6176): #13     _SinkTransformerStreamSubscription._add (dart:async/stream_transformers.dart:69:11)
E/flutter ( 6176): #14     _EventSinkWrapper.add (dart:async/stream_transformers.dart:15:11)
E/flutter ( 6176): #15     _StringAdapterSink.add (dart:convert/string_conversion.dart:238:11)
E/flutter ( 6176): #16     _StringAdapterSink.addSlice (dart:convert/string_conversion.dart:243:7)
E/flutter ( 6176): #17     _Utf8ConversionSink.addSlice (dart:convert/string_conversion.dart:317:20)
E/flutter ( 6176): #18     _Utf8ConversionSink.add (dart:convert/string_conversion.dart:310:5)
E/flutter ( 6176): #19     _ConverterStreamEventSink.add (dart:convert/chunked_conversion.dart:72:18)
E/flutter ( 6176): #20     _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:121:24)
E/flutter ( 6176): #21     _rootRunUnary (dart:async/zone.dart:1198:47)
E/flutter ( 6176): #22     _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter ( 6176): #23     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
E/flutter ( 6176): #24     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:357:11)
E/flutter ( 6176): #25     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:285:7)
E/flutter ( 6176): #26     _SinkTransformerStreamSubscription._add (dart:async/stream_transformers.dart:69:11)
E/flutter ( 6176): #27     _EventSinkWrapper.add (dart:async/stream_transformers.dart:15:11)
E/flutter ( 6176): #28     _HandlerEventSink.add (dart:async/stream_transformers.dart:227:12)
E/flutter ( 6176): #29     _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:121:24)
E/flutter ( 6176): #30     _rootRunUnary (dart:async/zone.dart:1198:47)
E/flutter ( 6176): #31     _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter ( 6176): #32     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
E/flutter ( 6176): #33     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:357:11)
E/flutter ( 6176): #34     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:285:7)
E/flutter ( 6176): #35     _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:127:11)
E/flutter ( 6176): #36     _HandleErrorStream._handleData (dart:async/stream_pipe.dart:266:10)
E/flutter ( 6176): #37     _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:157:13)
E/flutter ( 6176): #38     _rootRunUnary (dart:async/zone.dart:1198:47)
E/flutter ( 6176): #39     _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter ( 6176): #40     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
E/flutter ( 6176): #41     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:357:11)
E/flutter ( 6176): #42     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:285:7)
E/flutter ( 6176): #43     _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:127:11)
E/flutter ( 6176): #44     _HandleErrorStream._handleData (dart:async/stream_pipe.dart:266:10)
E/flutter ( 6176): #45     _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:157:13)
E/flutter ( 6176): #46     _rootRunUnary (dart:async/zone.dart:1198:47)
E/flutter ( 6176): #47     _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter ( 6176): #48     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
E/flutter ( 6176): #49     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:357:11)
E/flutter ( 6176): #50     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:285:7)
E/flutter ( 6176): #51     _SyncStreamControllerDispatch._sendData (dart:async/stream

Manish Vlog

unread,
Feb 8, 2021, 1:41:15 AM2/8/21
to Raman Plaha, Flutter Development (flutter-dev)

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/0bfb1935-e63c-4715-af2a-9261f5000ce1n%40googlegroups.com.

Suzuki Tomohiro

unread,
Feb 8, 2021, 8:31:48 AM2/8/21
to Raman Plaha, Flutter Development (flutter-dev)
From the server-side perspective, what’s difference between the successful request and unsuccessful one? If you’re not sure, ask the maintainer of the server system.

Reply all
Reply to author
Forward
0 new messages