I have a nodejs rest service that receives multiple files as multipart form where each element has a filename key and the actual file data.
The server part works fine (I can successfully upload files from javascript) and looks like this:
router.post("/upload_temp_resource", function(req, res){
req.setTimeout(0);
var form = new multiparty.Form();
var id = String(new Date().getTime());
var base = path.join(os.tmpdir(), id);
var manifest = null;
var files = [];
form.on("part", function(part){
if (!part.filename) return;
var dest = path.join(base, part.name);
files.push(part.name);
mkdirp(path.dirname(dest), function(err){
// ignore err if folder exists
var stream = part.pipe(fs.createWriteStream(dest));
});
if (part.name=="imsmanifest.xml")
manifest = true;
});
...
The client side Javascript (which also works fine) looks like this:
var fd = new FormData();
files.forEach(function(file){
fd.append(joinPaths(file._relativePath || "", file.name), file);
});
And fd
is posted through XMLHttpRequest
.
Now I need to do the same (client part) in c#. I've tried various examples found in stackoverflow but all of them generates exceptions on nodejs side (Error: stream ended unexpectedly
or Error: content-type missing boundary
etc)
via lviggiani
No comments:
Post a Comment