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

Fix cannot read file from path using rest.file() #252

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 11 additions & 20 deletions lib/multipartform.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var fs = require('fs');
var sys = require('util')
var sys = require('util');
exports.defaultBoundary = '48940923NODERESLTER3890457293';


Expand Down Expand Up @@ -109,25 +109,16 @@ Part.prototype = {

//Now write out the body of the Part
if (this.value instanceof File) {
fs.open(this.value.path, "r", 0666, function (err, fd) {
if (err) throw err;

var position = 0;

(function reader () {
fs.read(fd, 1024 * 4, position, "binary", function (er, chunk) {
if (er) callback(err);
stream.write(chunk);
position += 1024 * 4;
if (chunk) reader();
else {
stream.write("\r\n")
callback();
fs.close(fd);
}
});
})(); // reader()
});
fs.readFile(this.value.path, (err, fileBuff) => {
"use strict";
if (err) {
throw err;
}

stream.write(fileBuff);
stream.write("\r\n");
callback();
});
} else if (this.value instanceof Data) {
stream.write(this.value.data);
stream.write("\r\n");
Expand Down