Closed rico345100 closed 7 years ago
guys, I load the script directly without bundling by browserify, it works. But something another happened. Look at this server side code:
ss(socket).on('/user/update/profile', (stream, data) => {
const filename = path.basename(data.name);
const ws = fs.createWriteStream(`userdata/profile/${filename}`);
stream.on('error', (e) => {
console.log('Error found:');
console.log(e);
});
stream.on('drain', (e) => {
console.log('drain');
});
stream.on('data', () => {
console.log('data');
});
stream.on('close', () => {
console.log('close');
});
stream.pipe(ws);
});
When I was sent file from browser with socket.io-stream, it works. But when I tried with Electron, it won't work with this error message:
TypeError: Invalid non-string/buffer chunk
I saw similar issue, not Electron, nw.js. He found some solution but it didn't worked for me. I logged every data sending from client on Electron's BrowserWindow(console of inspector I mean), looks like it sent well:
var file = ev.target.files[0];
var stream = ss.createStream();
ss(socket).emit('/user/update/profile', stream, {
email: this.props.user.email,
name: file.name,
size: file.size
});
var blobStream = ss.createBlobReadStream(file);
var size = 0;
blobStream.on('data', (chunk) => {
size += chunk.length;
console.log(`${size} / ${file.size}`);
});
blobStream.pipe(stream);
and this is what console logged:
16384 / 4514096
app.js:63105 32768 / 4514096
app.js:63105 49152 / 4514096
app.js:63105 65536 / 4514096
...
app.js:63105 4505600 / 4514096
app.js:63105 4514096 / 4514096
Client sent the data without any error, but server failed to create file with error. What should I do?
I have used the file directly, by placing it in some of my folder, it also worked for me.
But if am using browserify, it gives me error chunk.toArrayBuffer is not a function
I'm having the same issue but I'm using JSPM.
Any idea?
Guys, I was able to solve this by using:
socketStream.forceBase64 = true
Regards.
Got the same issue with node-webterm which uses terminal.js and browserify.
Just by the way you guys, this is because Browserify handles chunks differently. I have a PR open to fix this that hasn't been merged: https://github.com/nkzawa/socket.io-stream/pull/86
If you want I have a fork here that has the single commit. It's what I've been using at my company. That's here: https://github.com/colwynmyself/socket.io-stream
Fixed!
When I'm sending file, always fails with:
message from client(latest chrome browser) and this is my client src:
and this is server code:
I'm using node -v 6.2.2. What is the problem?
\ note: I used browserify to move socket.io-stream.js file into client. Why I told this because I saw the comment:
// socket.io can't handle Buffer when using browserify. chunk = chunk.toArrayBuffer();