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

Detect content-type during addFile #38

Open
sntran opened this issue Jun 1, 2012 · 0 comments
Open

Detect content-type during addFile #38

sntran opened this issue Jun 1, 2012 · 0 comments

Comments

@sntran
Copy link

sntran commented Jun 1, 2012

Hi,

Currently I have a request stream and I pass that stream to node-cloudfiles' addFile as

cloudfile.addFile("container", "{remote: "fileName.ext", stream: readStream}, callback)

However, since the request stream has content-type set to application/octet-stream, it is saved as application/octet-stream in Rackspace.

From core.js:addFile:

addOptions = {
  method: 'PUT',
  client: this,
  upload: lstream,
  uri: this.storageUrl(container, options.remote),
  headers: options.headers || {}
};

if (options.headers && !options.headers['content-type']) {
  options.headers['content-type'] = mime.lookup(options.remote);
}

Understandably, it will only try to look up MIME type when options.headers is set, so for my above code to work, I would include a headers: {} in the options argument.

My question is, I'm not sure why it only tries to detect when options.headers is set. I, for one, would not want to do any thing with the request headers, yet still want the MIME to be look up immediately.

Would changing to the below in core.js:addFile cause any problem?

addOptions = {
  method: 'PUT',
  client: this,
  upload: lstream,
  uri: this.storageUrl(container, options.remote),
  headers: options.headers || {}
};

if (!addOptions.headers['content-type']) {
  addOptions.headers['content-type'] = mime.lookup(options.remote);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant