Skip to content

Issue with AddFile on Request #1714

@iamsubingyawali

Description

@iamsubingyawali

I am using Restsharp to send a POST request to my REST API running Laravel. Specifically, what I am trying to do is to create a new user from my WPF app which sends some user details and profile image as post params. I tried the same thing with Postman and it is working fine but it didn't work as expected while using Restsharp. I am getting PHP Warning: File Upload Mime headers garbled in Unknown on line 0 on my Laravel server.

Code I am using:

RestRequest restRequest = new RestRequest("user", Method.Post); 
restRequest.AlwaysMultipartFormData = true;
restRequest.AddHeader("Content-Type", "multipart/form-data");

// Adding other post params
// post_data is a dictionary: Dictionary<string, object> post_data;
post_data.Add("firstname", FirstNameField.Text.Trim());
// and so on
restRequest.AddJsonBody(post_data);

// Adding files
// profile_image is link to the file: E:\MyFiles\Pictures\Screenshots\Screenshot (7).png
restRequest.AddFile("photo", profile_image);
var response_json = await client.ExecuteAsync<JObject>(restRequest);

Environment

  • OS: Windows 11
  • .NET5 WPF
  • Version 107.1.1
  • Server: Laravel v8.58.0 (PHP v8.0.13)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions