Reputation: 7150
I need to upload an image to server with header, body and token using http package.
http.MultipartRequest imageUploadRequest = http.MultipartRequest('POST', Uri.parse(BASE_URL));
imageUploadRequest.headers["Authorization"] = "bearer ${token}";
imageUploadRequest.fields['FileName'] = "Test";
final file = await http.MultipartFile.fromPath('file', image.path);
imageUploadRequest.files.add(file);
final streamedResponse = await imageUploadRequest.send();
print("streamedResponse.statusCode : ${streamedResponse.statusCode}");
// Log-> streamedResponse.statusCode : 307
print("streamedResponse.headers : ${streamedResponse.headers}");
// Log-> streamedResponse.headers : streamedResponse.headers : {x-powered-by: ASP.NET, location: https://api.test.me/image, date: Sat, 23 Nov 2019 05:01:48 GMT, transfer-encoding: chunked, server: Microsoft-IIS/10.0}
final MapString, dynamic responseData = json.decode(response.body);
print("statusCode : ${response.statusCode}");
// Log-> statusCode : 307
print("headers : ${response.headers}");
// Log-> headers : streamedResponse.headers : {x-powered-by: ASP.NET, location: https://api.test.me/image, date: Sat, 23 Nov 2019 05:01:48 GMT, transfer-encoding: chunked, server: Microsoft-IIS/10.0}
But, I got the following error "Error : FormatException: Unexpected end of input (at character 1)" with status code 307.
Can anyone please tell me what is the problem?
My headers are not matching as i am passing with the fields!!!
This code is working fine in my another application with multipart file upload.
Thanks.
Upvotes: 0
Views: 580
Reputation: 51750
HTTP status 307 is a redirect, so the server is telling you to try the request again using the different URL that it's given you in the location header of the response (i.e. https://api.test.me/image
). You either need to retry the request, or send the initial request to the correct endpoint so that the server doesn't send a redirect.
Upvotes: 1