none
Problem sending file to Post using MultipartFormDataContent RRS feed

  • Question

  • Hi,

    I am using below code to upload a file from my C# to my PHP host.

    I am able to get all the StringContent but not able to get the file.

    When checking the ms.Length I can see the file has the correct size but when it goes to PHP I don’t know why it’s zero size.

    In PHP I am using:

    $file_name = '../mosques/' . $mousque_guid . '.png';
        
    move_uploaded_file($_FILES['MosqueFile']['tmp_name'], $file_name);
    

    Is there anything I should add in my C#?

    and this is my code:

    MultipartFormDataContent multipartContent = new MultipartFormDataContent();
    multipartContent.Add(new StreamContent(ms), "MosqueFile", Guid.NewGuid().ToString() + ".png");
    multipartContent.Add(new StringContent(EntryMouqueFirstName.Text), "first_name");
    multipartContent.Add(new StringContent(EntryMouqueFamilyName.Text), "last_name");
    multipartContent.Add(new StringContent(EntryMouqueEmailAddress.Text), "email");
    multipartContent.Add(new StringContent(EntryMouqueName.Text), "mosque");
    multipartContent.Add(new StringContent(CountryCode), "country");
    
    var response = await client.PostAsync("https://my.domain.com/ws/submit_mouque.php", multipartContent);
    var result = await response.Content.ReadAsStringAsync();
    

    Thanks,
    Jassim

    Tuesday, September 4, 2018 4:43 AM

Answers

  • Maybe you should execute ‘ms.Position = 0’ before this code?

    See also WebClient.UploadFile.


    • Marked as answer by Jassim Rahma Tuesday, September 4, 2018 3:30 PM
    Tuesday, September 4, 2018 5:06 AM

All replies