Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to access the file path and original file name in the rename function? #52

Closed
codeniac opened this issue Aug 8, 2014 · 3 comments
Labels

Comments

@codeniac
Copy link

codeniac commented Aug 8, 2014

I try to rename an incoming file chunk accessing the filename parameter, but the filename is set to "blob"!! I think i misunderstand the hole concept of file uploading.... in my mind the process is something like this: the file is sent from client to server one chunk at a time that is stored in a temporary folder and after completion i must resemble this temporary chunks into the sent file and move it to a permanent folder! I was using Flow.js to allow a "smarter" upload process where the client check what chunks was already uploaded and start from there in case of some previous failure, but i'm having trouble to integrate multer with Flow.js to have this nice functionality on! Anyone could help my stupidity in this matter? :)

@jpfluger
Copy link
Contributor

Multer's files are the completely assembled file (all chunks combined).

Multer uses busboy for parsing html multipart data. In busboy, an event is not emitted for chunks of files. An event is emitted for having uploaded the entire file. See busboy code, lines 189 - 205. According to the node docs, FileStream does support the data event, which will return the chunks you need.

You could post an issue on busboy and see if they might emit the chunk event but beyond that I'm not sure what to suggest. At the multer level, we could take the emitted chunk and write it to file. Is this all you'd need? If so, I think there's hope... but this is where my knowledge quickly thins: you'll need a way to figure out if the incoming data started in the middle of the file upload or if it was just beginning. (chuck mgmt process?) If you can step through the logic to implement this, maybe someone reading could take a stab at it?

Sorry, I have no real good answers for you. But maybe someone else will have more insight or know of other resources to do this.

@jpfluger
Copy link
Contributor

You know.... I slept on this. Multer already has options.onFileUploadData, which emits the event for data. You have the chunks here but these chunks aren't saved to file. When I added the option.inMemory last night, it also includes a new file.buffer property. Within onFileUploadData(file, data), file.buffer would contain the data chunk plus any preceding chunks, whereas the data param would be that single chunk. Hope that helps.

@jpfluger
Copy link
Contributor

The onFileUpload* functions now include req and res. That doesn't give you minute control over file chunks but is a step closer. Now you can get a socket.io instance attached to your req or res session and report back to the client upload progress. Again, it's not allowing for chunked memory management on the server but will create a more responsive app for the client.

@jpfluger jpfluger closed this as completed May 1, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants