Fix Coding Problem for app (xamarin)
$30-250 AUD
Paid on delivery
I am trying to make an API call from xamarin, this is my first Full mobile app calling restful API (.NetCore3.1) with a Angular WebApp. All other API calls from the xamarin app are working, The issue is I need to send a File with an object, file can be .doc .png etc.
[login to view URL] API Endpoint
public class FileProvider { public string GA { get; set; } public IList<IFormFile> Files { get; set; } } [HttpPost] [Route("[action]")] public ActionResult SubmitGrantApplication([FromForm] FileProvider fileProvider) { try { var ga = fileProvider; byte[] fileContent = null; var files = [login to view URL]() ? [login to view URL] : new FormFileCollection(); var grant = [login to view URL]<GrantApplication>([login to view URL]); ... } }
[login to view URL] Call made from the mobile app: This call is returning a 400 response with no clear indication why. I am trying to figure out why, And my postman skills aren't that great to convert the code to postman.
The error returned at #5.
::"Object reference not set to an instance of an object."
public class GrantService { public static async Task<GrantApplication> SubmitGrant(GrantApplication ga,string file, string FileName, StreamContent FileData) { Uri requestUri = new Uri($"{[login to view URL]}/grantapplication/SubmitGrantApplication"); try { var upfilebytes = [login to view URL](file); //using (HttpClient client = new HttpClient()) //{ // //MultipartFormDataContent content = new MultipartFormDataContent(); // //ByteArrayContent baContent = new ByteArrayContent(upfilebytes); // //StringContent GA = new StringContent([login to view URL](ga)); // //[login to view URL](baContent, "Files", FileName); // //[login to view URL](GA, "GA"); // //[login to view URL](content); // //var response = await [login to view URL](requestUri, content); // //[login to view URL](await [login to view URL]()); // //return ga; //} using (var formContent = new MultipartFormDataContent()) { [login to view URL] = "multipart/form-data"; // 3. Add the filename C:\\... + fileName is the path your file Stream fileStream = [login to view URL](file); [login to view URL](new StreamContent(fileStream), FileName, FileName); var payload = [login to view URL](ga); HttpContent content = new StringContent(payload, [login to view URL], "application/json"); [login to view URL](content, "GA"); using (var client = new HttpClient()) { // Bearer Token header if needed [login to view URL](new MediaTypeWithQualityHeaderValue("multipart/form-data")); try { // 4.. Execute the MultipartPostMethod var message = await [login to view URL](requestUri, formContent); // 5.a Receive the response var result = await [login to view URL](); [login to view URL](result); } catch (Exception ex) { // Do what you want if it fails. throw ex; } } } return ga; } catch(Exception ex) { [login to view URL](ex); return ga; } } }
Web System Angular API call
public SubmitGrantApplication(grantApplication){ [login to view URL] = [login to view URL]([login to view URL]("LoggedInUser")).memberID; [login to view URL] = [login to view URL]([login to view URL]("LoggedInUser")).clientID; [login to view URL] = new HttpHeaders({ 'Content-Type' : 'multipart/form-data' }); [login to view URL] = new HttpHeaders({ 'Accept': 'multipart/form-data'}); let myFormData: FormData = new FormData(); [login to view URL]("Files", [login to view URL]); [login to view URL]("GA", [login to view URL](grantApplication)); return [login to view URL]<GrantApplication>(this.url+"SubmitGrantApplication", myFormData , { headers: [login to view URL] }).pipe( ).toPromise(); }
Swagger
Swagger Doc
Works Angular API Call Works Payload Angular
Project ID: #30612403
About the project
5 freelancers are bidding on average $204 for this job
Hello. I reviewed your request carefully. I can complete your task. I have 10 years of c# development experience. I am familiar with php、wordpress. SQL、asp.net、mvc、.net core、 html、 css、React、vue、angular、 jquery、 Jav More
Hi, I hope you are doing well! I came across your project details and wanted to get in touch with you regarding your project that you are looking for experienced Xamarin developer with good knowledge of c# and .net f More