Open ChristophHaag opened 10 years ago
Well yes, this is an old example and needs a good rewrite. Example could even be rewritten on other nodejs framework. Maybe somebody could collaborate on this?
i'm having a ton of issues with this too. i haven't found a good middleware to handle the multipart/formdata.
suggestions?
i made a pull request to fix this. i did not update the read.me in the pull.... maybe i'll make another.
also!
i'm having an issue assembling the binary from the blobs, if you're into stackoverflow points, you could answer my question (and the two other unanswered questions that are essentially the same question): http://stackoverflow.com/questions/23449065/reassemble-binary-after-flow-js-upload-on-node-express-server
Reassembling all chunks is easy, just call this:
var stream = fs.createWriteStream(filename);
r.write(identifier, stream);
And that is it!
But other question is, when this method should be called?
Maybe then all chunks are uploaded and present at tmp
folder.
https://github.com/flowjs/flow.js/blob/master/samples/Node.js/flow-node.js#L122
And another issue is solved.
But there is another issue with duplicate calls of done
: https://github.com/flowjs/flow.js/issues/16
This can be solved by creating and locking the file, once all chunks exists.
Then call r.write(identifier, stream);
Then clean all chunks. https://github.com/flowjs/flow.js/blob/master/samples/Node.js/flow-node.js#L182
Then release the lock and close the file.
Same approuch is done in php server side library: https://github.com/flowjs/flow-php-server/blob/master/src/Flow/File.php#L102
Hope this helps, and I hope someone could collaborate and update node.js
sample with these fixes.
It worked for me (now that I'm on the right server). But there is no method for deleting.
@chovy Any chance this solution could be added to the example? I'm trying to figure it out, I understand what is happening here, but I can't seem to produce the result.
I decided not to use flow.js infavor of a custom handler.
@AidasK Any chance you can provide a more complete answer with an example?
It looks like you've been pasting the same solution in a number of places (stackoverflow), but don't really go into any depth to explain it.
It isn't me posting in stackoverflow with this solution, somebody else is trying to earn some points.
The reason, why I don't provide a normal nodejs solution, is because this sample is not written by me. And I hate how it looks https://github.com/flowjs/flow.js/blob/master/samples/Node.js/flow-node.js This sample needs a rewrite.
If you are just trying to play with flow.js or Nodejs is not neccessary, you should try php library instead: https://github.com/flowjs/flow-php-server
@AidasK strange about the SO person.. what a lame thing to do. Anyway, I worked with this most of yesterday and came up with this, if anything, maybe it's a good starting point for someone more experienced than me:
exports.post = function (req, res, next) {
flow.post(req, function(status, filename, original_filename, identifier) {
console.log('status: '+ status, filename, original_filename, identifier);
if(status==='done'){
var s = fs.createWriteStream('./uploads/' + filename);
s.on('finish', function() {
res.send(200, {
// NOTE: Uncomment this funciton to enable cross-domain request.
//'Access-Control-Allow-Origin': '*'
});
});
flow.write(identifier, s, {end: true});
}
});
};
This might work, but be careful with simultaneous uploads, because status
done
might occur multiple times for the same file.
@AidasK You're right, i've only needed it for a single file. Thank you for the feedback.
Hi @AidasK and @flashpunk, I applied the solution from StackOverflow. However, I don't know how to set the destination directory programatically. I would like to write my files to directories in format /uploads/YYYY/mm/dd/filename . However, changing the destination directory from './tmp/' to '/uploads' broke the code.
It would be really, really nice if we had a working example of flow-node.js .
Thanks.
@MilosStanic You can set the chunk directory by modifying these two lines in the example: https://github.com/flowjs/flow.js/blob/master/samples/Node.js/app.js#L1 and https://github.com/flowjs/flow.js/blob/master/samples/Node.js/app.js#L6
To store the resulting file in a custom directory, I've added
var stream = fs.createWriteStream(UPLOAD_DIR + '/' + filename);
flow.write(identifier, stream);
here: https://github.com/flowjs/flow.js/blob/master/samples/Node.js/app.js#L19
Does this answer your question?
@Powernap thanks, I solved my issues with Flow weeks ago. I don't really remember what I did. But I'm using Flow for my web app. And I like it.
Hope that this implementation is helpful for you guys (re-write in ES6 & use Bluebird Promise)
https://gist.github.com/ptgamr/4d1d07b770321a138c91
@AidasK Do you think it's good enough for a pull request?
@ptgamr Looks awesome and clean. If you can, please update node.js sample with your code. I would be glad to accept it.
First, the Readme is outdated. It says to do
npm install express
but this downloads express 4.0 now, but the code depends on express 3.x.So it should say
npm install express@3.x
until it is fixed for 4.x.Then the upload simply never finishes on the server side.
I actually first tried the node.js sample from resume.js and after it worked fine I tried to change the directory of the uploaded files and at this point point it did the same which the sample here does:
The line
POST done <filename>
doesn't appear on the server side log (onlypartly_done
for all the chunks), but on the browser side it saysfileSuccess FlowFile [...] complete
. The samples/Node.js/tmp directory remains empty.I haven't really tested more and I don't think I have much motivation right now to do it.
node v0.10.26 chromium Version 35.0.1916.17