Hello!
Not really sure if this is the right place to post this question, but here goes nothing.
I’ve been working on an app that lets you create models within Unity, and i’ve got everything working except my interface with the web marketplace.
I need to be able to send these files into my Node server in order to do a number of things but i am stuck on a step that i thought would be simple:
I can’t actually get the data to go through without the stream ending unexpectedly, or there being no data transferred on the other end (despite the Content-Length clearly growing and shrinking depending on what i add.)
Here is my code from Unity:
IEnumerator UploadFileToServer()
{
List<IMultipartFormSection> Data = new List<IMultipartFormSection>();
Data.Add(new MultipartFormDataSection("SomeField", "SomeData"));
Data.Add(new MultipartFormDataSection("SomeMoreFields", "SomeMOREData"));
Data.Add(new MultipartFormFileSection("FuckinFile", UnityWebRequest.GenerateBoundary()));
UnityWebRequest request = UnityWebRequest.Post(EndPoint, Data);
yield return request.Send();
if (request.isError)
{
Debug.Log("Error " + request.error);
}
else
{
Debug.Log("Form upload complete!");
foreach (KeyValuePair<string, string> stuff in request.GetResponseHeaders())
{
Debug.Log("Got response header: key: " + stuff.Key + " val: " + stuff.Value);
}
}
}
And once i send that through, i hit node:
At first, i used “Multiparty” which kept getting “Stream ended unexpectedly”
Heres the code for that:
exports.PostNewModelUnity = function (req, res) {
console.log("Got new post from unity, parsing...");
var form = new multiparty.Form();
//console.log(req.method);
console.log(util.inspect(req.headers));
console.log(util.inspect(req.body));
form.parse(req, function (err, fields, files) {
if (err) {
console.log("Errored parsing req from unity: " + err);
} else {
console.log("Succesfully got post from Unity");
console.log(fields);
console.log(files);
util.inspect({
fields: fields,
files: files
});
res.end("Got some request");
}
});
}
Afterwards, i tried using “Multer” but i just don’t seem to have any data within the body, or the files field after trying to parse it with the “Any()” command, i tried “Array(), Fields(), None(), etc…” to no avail.
exports.PostNewModelUnity = function (req, res,next) {
console.log("Got new post from unity, parsing...");
console.log(util.inspect(req.headers));
console.log("body");
console.log(util.inspect(req.body));
console.log("files");
console.log(util.inspect(req.files));
}
I’ve been trying different options, so many that i don’t even know where to begin, and i kind of gave up for a month or two before getting back into it last night.
There was this post
And i tried doing what this dude did, to no avail. It changed from “stream ended unexpectedly” to “Content-Type missing boundary”…
Please give me a hand, my app is totally halted until i can get this working, and i am completely friggen lost.
PS. If i posted in the wrong section, please let me know so i can repost.
Thanks,
- Sol.