simonwittber / uniwebserver

An embedded HTTP server for Unity3D.
MIT License
76 stars 30 forks source link

Unable to save form submitted image file #1

Open hyakugei opened 7 years ago

hyakugei commented 7 years ago

Using both the following code examples, i am unable to convert the MultipartFormEntry.Value into a valid image file. Note that these lines have been added to the example FileUpload class.

Example 1

public void HandleRequest (Request request, Response response)
{
    var mpf = MultiPartEntry.Parse(request);
    var filePath = Path.Combine(Application.dataPath, "Image.png");
    var bytes = System.Text.Encoding.UTF8.GetBytes(mpf["fileToUpload"].Value);
    File.WriteAllBytes(filePath, bytes);

    response.statusCode = 200;
    response.message = "OK.";
    response.Write(html.text);
}

Example 2

public void HandleRequest (Request request, Response response)
{
    var mpf = MultiPartEntry.Parse(request);
    var filePath = Path.Combine(Application.dataPath, "Image.png");
    File.WriteAllText(filePath, mpf["fileToUpload"].Value);

    response.statusCode = 200;
    response.message = "OK.";
    response.Write(html.text);
}

This the original file on the left, and the saved file on the right. Will continue to test.

sel_140

Personuo commented 3 years ago

Hello, have you solved this problem?

hyakugei commented 3 years ago

I never found a fix.

Personuo commented 3 years ago

Have you later found any way for unity to act as an http server and send files to unity via the web client? I want players to be able to upload their pictures and mp3 files to unity via the web.

hyakugei commented 3 years ago

Nothing public, it was 3 years ago i was working on this, and i can't even remember how i solved it, or even if i solved it. Sorry.

Personuo commented 3 years ago

Nothing public, it was 3 years ago i was working on this, and i can't even remember how i solved it, or even if i solved it. Sorry.

Ok,thank you for this reply.Good day.